/**
 * @ai-summary Type definitions for maintenance receipt OCR extraction
 * @ai-context Mirrors fuel-logs ExtractedReceiptField pattern; maps OCR fields to maintenance record form values
 */

import { MaintenanceCategory } from './maintenance.types';

/** OCR-extracted field with confidence score */
export interface ExtractedMaintenanceField {
  value: string | number | null;
  confidence: number;
}

/** Fields extracted from a maintenance receipt via OCR */
export interface ExtractedMaintenanceReceiptFields {
  serviceName: ExtractedMaintenanceField;
  serviceDate: ExtractedMaintenanceField;
  totalCost: ExtractedMaintenanceField;
  shopName: ExtractedMaintenanceField;
  laborCost: ExtractedMaintenanceField;
  partsCost: ExtractedMaintenanceField;
  odometerReading: ExtractedMaintenanceField;
  vehicleInfo: ExtractedMaintenanceField;
}

/** Suggested category and subtypes from service name keyword matching */
export interface CategorySuggestion {
  category: MaintenanceCategory;
  subtypes: string[];
  confidence: number;
}

/** Mapped fields ready for maintenance record form population */
export interface MappedMaintenanceFields {
  date?: string;
  cost?: number;
  shopName?: string;
  odometerReading?: number;
  category?: MaintenanceCategory;
  subtypes?: string[];
  notes?: string;
}

/** Maintenance receipt OCR result */
export interface MaintenanceReceiptOcrResult {
  extractedFields: ExtractedMaintenanceReceiptFields;
  mappedFields: MappedMaintenanceFields;
  categorySuggestion: CategorySuggestion | null;
  rawText: string;
  overallConfidence: number;
}

/** Hook state */
export interface UseMaintenanceReceiptOcrState {
  isCapturing: boolean;
  isProcessing: boolean;
  result: MaintenanceReceiptOcrResult | null;
  receiptImageUrl: string | null;
  error: string | null;
}

/** Hook return type */
export interface UseMaintenanceReceiptOcrReturn extends UseMaintenanceReceiptOcrState {
  startCapture: () => void;
  cancelCapture: () => void;
  processImage: (file: File, croppedFile?: File) => Promise<void>;
  acceptResult: () => MappedMaintenanceFields | null;
  reset: () => void;
  updateField: (fieldName: keyof ExtractedMaintenanceReceiptFields, value: string | number | null) => void;
}
