/**
 * @ai-summary TypeScript types for OCR feature
 */

/** Types of documents that can be processed by OCR */
export type DocumentType = 'vin' | 'receipt' | 'manual' | 'unknown';

/** A single extracted field with confidence score */
export interface ExtractedField {
  value: string;
  confidence: number;
}

/** Response from OCR extraction */
export interface OcrResponse {
  success: boolean;
  documentType: DocumentType;
  rawText: string;
  confidence: number;
  extractedFields: Record<string, ExtractedField>;
  processingTimeMs: number;
}

/** Status of an async OCR job */
export type JobStatus = 'pending' | 'processing' | 'completed' | 'failed';

/** Response for async job status */
export interface JobResponse {
  jobId: string;
  status: JobStatus;
  progress?: number;
  result?: OcrResponse;
  error?: string;
}

/** Request to submit an async OCR job */
export interface JobSubmitRequest {
  callbackUrl?: string;
}

/** Internal request to OCR service */
export interface OcrExtractRequest {
  fileBuffer: Buffer;
  contentType: string;
  preprocess?: boolean;
}

/** Response from receipt-specific extraction */
export interface ReceiptExtractionResponse {
  success: boolean;
  receiptType: string;
  extractedFields: Record<string, ExtractedField>;
  rawText: string;
  processingTimeMs: number;
  error: string | null;
}

/** Request for receipt extraction */
export interface ReceiptExtractRequest {
  fileBuffer: Buffer;
  contentType: string;
  receiptType?: string;
}

/** Request for maintenance receipt extraction */
export interface MaintenanceReceiptExtractRequest {
  fileBuffer: Buffer;
  contentType: string;
}

/** Response from VIN-specific extraction */
export interface VinExtractionResponse {
  success: boolean;
  vin: string | null;
  confidence: number;
  boundingBox: { x: number; y: number; width: number; height: number } | null;
  alternatives: { vin: string; confidence: number }[];
  processingTimeMs: number;
  error: string | null;
}

/** Internal request to submit async job */
export interface OcrJobSubmitRequest {
  fileBuffer: Buffer;
  contentType: string;
  callbackUrl?: string;
}

/** Request to submit a manual extraction job */
export interface ManualJobSubmitRequest {
  fileBuffer: Buffer;
  contentType: string;
  vehicleId?: string;
}

/** Vehicle info extracted from a manual */
export interface ManualVehicleInfo {
  make: string | null;
  model: string | null;
  year: number | null;
}

/** A single maintenance schedule item extracted from a manual */
export interface MaintenanceScheduleItem {
  service: string;
  intervalMiles: number | null;
  intervalMonths: number | null;
  details: string | null;
  confidence: number;
  subtypes: string[];
}

/** Result of manual extraction (nested in ManualJobResponse.result) */
export interface ManualExtractionResult {
  success: boolean;
  vehicleInfo: ManualVehicleInfo;
  maintenanceSchedules: MaintenanceScheduleItem[];
  rawTables: unknown[];
  processingTimeMs: number;
  totalPages: number;
  pagesProcessed: number;
  error: string | null;
}

/** Response for async manual extraction job */
export interface ManualJobResponse {
  jobId: string;
  status: JobStatus;
  progress?: number;
  estimatedSeconds?: number;
  result?: ManualExtractionResult;
  error?: string;
}
