import type { PipelineStep } from '../ocr-pipeline/types'

// Re-export types used by overlay components
export type {
  PipelineStep,
  PipelineStepStatus,
  SessionListItem,
  SessionInfo,
  DocumentCategory,
  DocumentTypeResult,
  OrientationResult,
  CropResult,
  DeskewResult,
  DewarpResult,
  RowResult,
  RowItem,
  GridResult,
  GridCell,
  OcrWordBox,
  WordBbox,
  ColumnMeta,
} from '../ocr-pipeline/types'

export { DOCUMENT_CATEGORIES } from '../ocr-pipeline/types'

/**
 * 7-step pipeline for full-page overlay reconstruction.
 * Skips: Spalten (columns), LLM-Review (Korrektur), Ground-Truth (Validierung)
 */
export const OVERLAY_PIPELINE_STEPS: PipelineStep[] = [
  { id: 'orientation', name: 'Orientierung', icon: '🔄', status: 'pending' },
  { id: 'deskew', name: 'Begradigung', icon: '📐', status: 'pending' },
  { id: 'dewarp', name: 'Entzerrung', icon: '🔧', status: 'pending' },
  { id: 'crop', name: 'Zuschneiden', icon: '✂️', status: 'pending' },
  { id: 'rows', name: 'Zeilen', icon: '📏', status: 'pending' },
  { id: 'words', name: 'Woerter', icon: '🔤', status: 'pending' },
  { id: 'reconstruction', name: 'Overlay', icon: '🏗️', status: 'pending' },
]

/** Map from overlay UI step index to DB step number (1-indexed) */
export const OVERLAY_UI_TO_DB: Record<number, number> = {
  0: 2,  // orientation
  1: 3,  // deskew
  2: 4,  // dewarp
  3: 5,  // crop
  4: 6,  // rows (skip columns=6 in DB, rows=7 — but we reuse DB step numbering)
  5: 7,  // words
  6: 9,  // reconstruction
}

/** Map from DB step to overlay UI step index */
export function dbStepToOverlayUi(dbStep: number): number {
  // DB: 1=start, 2=orient, 3=deskew, 4=dewarp, 5=crop, 6=columns, 7=rows, 8=words, 9=recon, 10=gt
  if (dbStep <= 2) return 0  // orientation
  if (dbStep === 3) return 1 // deskew
  if (dbStep === 4) return 2 // dewarp
  if (dbStep === 5) return 3 // crop
  if (dbStep <= 7) return 4  // rows (skip columns)
  if (dbStep === 8) return 5 // words
  return 6                   // reconstruction
}
