/**
 * File type detection result from magic byte analysis
 */
export interface FileTypeDetectionResult {
  mime: string;
  ext: string;
}

/**
 * Result of MIME type validation
 */
export interface ValidationResult {
  isValid: boolean;
  detectedMime: string;
  declaredMime: string;
  error?: string;
}

/**
 * Validation log entry for security auditing
 */
export interface ValidationLogEntry {
  timestamp: Date;
  userId?: string;
  fileSize: number;
  fileName?: string;
  declaredMime: string;
  detectedMime?: string;
  validationResult: 'success' | 'mismatch' | 'error';
  errorDetails?: string;
  module: 'record-management' | 'user-management' | 'external-portal';
  endpoint: string;
}

/**
 * Options for file upload validation
 */
export interface UploadValidationOptions {
  allowedMimeTypes: string[];
  maxFileSize?: number;
  logValidationEvents?: boolean;
}

/**
 * File validation state for tracking uploads
 */
export interface FileValidationState {
  fileId: string;
  uploadedAt: Date;
  declaredMimeType: string;
  detectedMimeType?: string;
  validationStatus: 'pending' | 'valid' | 'invalid' | 'error';
  validationError?: string;
  userId?: string;
  module: string;
}

/**
 * Context for XSS upload validation
 */
export interface XSSUploadValidationContext {
  allowedMimeTypes?: string[];
  allowedExtensions?: string[];
  maxSizeMB?: number;
  uploadContext: 'record' | 'external-portal' | 'incoming' | 'outgoing' | 'signature';
}

/**
 * Client-side validation details
 */
export interface ClientValidationDetails {
  passed: boolean;
  error?: string;
  fileName?: {
    passed: boolean;
    error?: string;
  };
  extension?: {
    passed: boolean;
    error?: string;
  };
  mimeType?: {
    passed: boolean;
    error?: string;
  };
  size?: {
    passed: boolean;
    error?: string;
  };
}

/**
 * Server-side validation details
 */
export interface ServerValidationDetails {
  passed: boolean;
  detectedMime: string;
  declaredMime: string;
  mimeMatch: boolean;
  allowedTypeMatch: boolean;
  error?: string;
}

/**
 * Result of XSS upload validation
 */
export interface XSSUploadValidationResult {
  isValid: boolean;
  clientValidation: ClientValidationDetails;
  serverValidation?: ServerValidationDetails;
  sanitizedFileName: string;
}

/**
 * XSS validation log entry for security auditing
 */
export interface XSSValidationLogEntry {
  timestamp: Date;
  userId?: string;
  fileName: string;
  sanitizedFileName: string;
  fileSize: number;
  declaredMimeType: string;
  detectedMimeType?: string;
  validationResult: 'success' | 'client-failed' | 'server-failed' | 'error';
  failureReason?: string;
  uploadContext: 'record' | 'external-portal' | 'incoming' | 'outgoing' | 'signature';
  module: 'record-management' | 'user-management' | 'external-portal';
}
