export type PipelineStepStatus = 'pending' | 'active' | 'completed' | 'failed'

export interface PipelineStep {
  id: string
  name: string
  icon: string
  status: PipelineStepStatus
}

export interface SessionListItem {
  id: string
  name: string
  filename: string
  status: string
  current_step: number
  created_at: string
  updated_at?: string
}

export interface SessionInfo {
  session_id: string
  filename: string
  name?: string
  image_width: number
  image_height: number
  original_image_url: string
  current_step?: number
  deskew_result?: DeskewResult
  dewarp_result?: DewarpResult
  column_result?: ColumnResult
  row_result?: RowResult
  word_result?: WordResult
}

export interface DeskewResult {
  session_id: string
  angle_hough: number
  angle_word_alignment: number
  angle_applied: number
  method_used: 'hough' | 'word_alignment' | 'manual'
  confidence: number
  duration_seconds: number
  deskewed_image_url: string
  binarized_image_url: string
}

export interface DeskewGroundTruth {
  is_correct: boolean
  corrected_angle?: number
  notes?: string
}

export interface DewarpResult {
  session_id: string
  method_used: 'vertical_edge' | 'manual' | 'none'
  shear_degrees: number
  confidence: number
  duration_seconds: number
  dewarped_image_url: string
}

export interface DewarpGroundTruth {
  is_correct: boolean
  corrected_shear?: number
  notes?: string
}

export interface PageRegion {
  type: 'column_en' | 'column_de' | 'column_example' | 'page_ref'
      | 'column_marker' | 'column_text' | 'column_ignore' | 'header' | 'footer'
  x: number
  y: number
  width: number
  height: number
  classification_confidence?: number
  classification_method?: string
}

export interface ColumnResult {
  columns: PageRegion[]
  duration_seconds: number
}

export interface ColumnGroundTruth {
  is_correct: boolean
  corrected_columns?: PageRegion[]
  notes?: string
}

export interface ManualColumnDivider {
  xPercent: number  // Position in % of image width (0-100)
}

export type ColumnTypeKey = PageRegion['type']

export interface RowResult {
  rows: RowItem[]
  summary: Record<string, number>
  total_rows: number
  duration_seconds: number
}

export interface RowItem {
  index: number
  x: number
  y: number
  width: number
  height: number
  word_count: number
  row_type: 'content' | 'header' | 'footer'
  gap_before: number
}

export interface RowGroundTruth {
  is_correct: boolean
  corrected_rows?: RowItem[]
  notes?: string
}

export interface WordBbox {
  x: number
  y: number
  w: number
  h: number
}

export interface WordEntry {
  row_index: number
  english: string
  german: string
  example: string
  confidence: number
  bbox: WordBbox
  bbox_en: WordBbox | null
  bbox_de: WordBbox | null
  bbox_ex: WordBbox | null
  status?: 'pending' | 'confirmed' | 'edited' | 'skipped'
}

export interface WordResult {
  entries: WordEntry[]
  entry_count: number
  image_width: number
  image_height: number
  duration_seconds: number
  ocr_engine?: string
  summary: {
    total_entries: number
    with_english: number
    with_german: number
    low_confidence: number
  }
}

export interface WordGroundTruth {
  is_correct: boolean
  corrected_entries?: WordEntry[]
  notes?: string
}

export const PIPELINE_STEPS: PipelineStep[] = [
  { id: 'deskew', name: 'Begradigung', icon: '📐', status: 'pending' },
  { id: 'dewarp', name: 'Entzerrung', icon: '🔧', status: 'pending' },
  { id: 'columns', name: 'Spalten', icon: '📊', status: 'pending' },
  { id: 'rows', name: 'Zeilen', icon: '📏', status: 'pending' },
  { id: 'words', name: 'Woerter', icon: '🔤', status: 'pending' },
  { id: 'coordinates', name: 'Koordinaten', icon: '📍', status: 'pending' },
  { id: 'reconstruction', name: 'Rekonstruktion', icon: '🏗️', status: 'pending' },
  { id: 'ground-truth', name: 'Validierung', icon: '✅', status: 'pending' },
]
