/**
 * Shared TypeScript types for OCR Labeling UI.
 *
 * Single source of truth used by:
 *   - admin-lehrer  (ai/ocr-labeling)
 *   - website       (admin/ocr-labeling)
 */

/**
 * Available OCR Models
 *
 * - llama3.2-vision:11b: Vision LLM, beste Qualitaet bei Handschrift (Standard)
 * - trocr: Microsoft TrOCR, schnell bei gedrucktem Text
 * - paddleocr: PaddleOCR + LLM, 4x schneller durch Hybrid-Ansatz
 * - donut: Document Understanding Transformer, strukturierte Dokumente
 */
export type OCRModel = 'llama3.2-vision:11b' | 'trocr' | 'paddleocr' | 'donut'

export const OCR_MODEL_INFO: Record<OCRModel, { label: string; description: string; speed: string }> = {
  'llama3.2-vision:11b': {
    label: 'Vision LLM',
    description: 'Beste Qualitaet bei Handschrift',
    speed: 'langsam',
  },
  trocr: {
    label: 'Microsoft TrOCR',
    description: 'Schnell bei gedrucktem Text',
    speed: 'schnell',
  },
  paddleocr: {
    label: 'PaddleOCR + LLM',
    description: 'Hybrid-Ansatz: OCR + Strukturierung',
    speed: 'sehr schnell',
  },
  donut: {
    label: 'Donut',
    description: 'Document Understanding fuer Tabellen/Formulare',
    speed: 'mittel',
  },
}

export interface OCRSession {
  id: string
  name: string
  source_type: 'klausur' | 'handwriting_sample' | 'scan'
  description?: string
  ocr_model?: OCRModel
  total_items: number
  labeled_items: number
  confirmed_items: number
  corrected_items: number
  skipped_items: number
  created_at: string
}

export interface OCRItem {
  id: string
  session_id: string
  session_name: string
  image_path: string
  image_url?: string
  ocr_text?: string
  ocr_confidence?: number
  ground_truth?: string
  status: 'pending' | 'confirmed' | 'corrected' | 'skipped'
  metadata?: Record<string, unknown>
  created_at: string
}

export interface OCRStats {
  total_sessions?: number
  session_id?: string
  name?: string
  total_items: number
  labeled_items: number
  confirmed_items: number
  corrected_items: number
  skipped_items?: number
  pending_items: number
  exportable_items?: number
  accuracy_rate: number
  avg_label_time_seconds?: number
  progress_percent?: number
}

export interface TrainingSample {
  id: string
  image_path: string
  ground_truth: string
  export_format: 'generic' | 'trocr' | 'llama_vision'
  training_batch: string
  exported_at?: string
}

export interface CreateSessionRequest {
  name: string
  source_type: 'klausur' | 'handwriting_sample' | 'scan'
  description?: string
  ocr_model?: OCRModel
}

export interface ConfirmRequest {
  item_id: string
  label_time_seconds?: number
}

export interface CorrectRequest {
  item_id: string
  ground_truth: string
  label_time_seconds?: number
}

export interface ExportRequest {
  export_format: 'generic' | 'trocr' | 'llama_vision'
  session_id?: string
  batch_id?: string
}

export interface UploadResult {
  id: string
  filename: string
  image_path: string
  image_hash: string
  ocr_text?: string
  ocr_confidence?: number
  status: string
}
