/**
 * 表格结构类型定义
 */
export interface TableStructure {
  horizontal_lines: number[]
  vertical_lines: number[]
  table_bbox?: number[]
  row_height?: number
  col_widths?: number[]
  total_rows?: number
  total_cols?: number
  mode?: string
  modified_h_lines: number[]
  modified_v_lines: number[]
  image_rotation_angle?: number
  skew_angle?: number
  is_skew_corrected?: boolean
}

/**
 * 图片尺寸
 */
export interface ImageSize {
  width: number
  height: number
}

/**
 * 选中的线条
 */
export interface SelectedLine {
  type: 'h' | 'v'  // h=横线, v=竖线
  index: number
}

/**
 * 上传响应
 */
export interface UploadResponse {
  success: boolean
  image_base64: string
  structure: TableStructure
  image_size: ImageSize
  scale_factor: number
  ocr_data?: Record<string, unknown>
  suggested_filename?: string
  message?: string
}

/**
 * 分析参数
 */
export interface AnalyzeParams {
  y_tolerance?: number
  x_tolerance?: number
  min_row_height?: number
  method?: 'auto' | 'cluster' | 'mineru' | 'cell_index'
}

/**
 * 分析选项
 */
export interface AnalyzeOptions {
  method?: string
  y_tolerance?: number
  x_tolerance?: number
  min_row_height?: number
}

/**
 * 分析响应
 */
export interface AnalyzeResponse {
  success: boolean
  structure: TableStructure
  message?: string
}

/**
 * 保存请求
 */
export interface SaveRequest {
  structure: TableStructure
  image_base64?: string
  output_dir: string
  filename: string
  image_filename?: string
  overwrite_mode?: string
  structure_suffix?: string
  image_suffix?: string
  line_width?: number
  line_color?: number[]
}

/**
 * 保存响应
 */
export interface SaveResponse {
  success: boolean
  structure_path?: string
  image_path?: string
  message?: string
}

/**
 * 编辑器状态
 */
export interface EditorState {
  // 图片相关
  imageSrc: string | null
  imageSize: ImageSize
  scaleFactor: number
  
  // 结构相关
  structure: TableStructure
  ocrData: Record<string, unknown> | null
  
  // 交互状态
  selectedLine: SelectedLine | null
  zoom: number
  stagePos: { x: number; y: number }
  
  // 加载状态
  isLoading: boolean
  hasData: boolean
}

/**
 * 历史状态（用于撤销/重做）
 */
export interface HistoryState {
  undoStack: TableStructure[]
  redoStack: TableStructure[]
}
