/**
 * 공정 작업기준 컴포넌트 타입 정의
 */

// 작업 단계 정의 (사용자가 추가/삭제/이름변경 가능)
export interface WorkPhaseDefinition {
  key: string;
  label: string;
  sortOrder: number;
}

// 상세 유형 정의 (사용자가 추가/삭제 가능)
export interface DetailTypeDefinition {
  value: string;
  label: string;
}

// 데이터 소스 설정
export interface DataSourceConfig {
  itemTable: string;
  itemNameColumn: string;
  itemCodeColumn: string;
  routingVersionTable: string;
  routingFkColumn: string;
  routingVersionNameColumn: string;
  routingDetailTable: string;
  processTable: string;
  processNameColumn: string;
  processCodeColumn: string;
}

// 전체 Config
export interface ProcessWorkStandardConfig {
  dataSource: DataSourceConfig;
  phases: WorkPhaseDefinition[];
  detailTypes: DetailTypeDefinition[];
  splitRatio?: number;
  leftPanelTitle?: string;
  readonly?: boolean;
  /** 품목 목록 모드: all=전체, registered=등록된 품목만 */
  itemListMode?: "all" | "registered";
  /** 등록 모드 시 화면 코드 (자동 설정됨) */
  screenCode?: string;
}

// ============================================================
// 데이터 모델
// ============================================================

export interface ItemData {
  id: string;
  item_name: string;
  item_code: string;
}

export interface RoutingVersion {
  id: string;
  version_name: string;
  description?: string;
  created_date?: string;
  processes: RoutingProcess[];
}

export interface RoutingProcess {
  routing_detail_id: string;
  seq_no: string;
  process_code: string;
  process_name: string;
  is_required?: string;
  work_type?: string;
}

export interface WorkItem {
  id: string;
  routing_detail_id: string;
  work_phase: string;
  title: string;
  is_required: string;
  sort_order: number;
  description?: string;
  detail_count: number;
  created_date?: string;
}

export interface WorkItemDetail {
  id: string;
  work_item_id: string;
  detail_type?: string;
  content: string;
  is_required: string;
  sort_order: number;
  remark?: string;
  created_date?: string;
  // 검사항목 전용
  inspection_code?: string;
  inspection_method?: string;
  unit?: string;
  lower_limit?: string;
  upper_limit?: string;
  // 작업절차 전용
  duration_minutes?: number;
  // 직접입력 전용
  input_type?: string;
  // 정보조회 전용
  lookup_target?: string;
  display_fields?: string;
}

export interface InspectionStandard {
  id: string;
  inspection_code: string;
  inspection_item: string;
  inspection_method: string;
  unit: string;
  lower_limit?: string;
  upper_limit?: string;
}

// ============================================================
// 컴포넌트 Props
// ============================================================

export interface ProcessWorkStandardComponentProps {
  config: ProcessWorkStandardConfig;
  formData?: Record<string, any>;
  isPreview?: boolean;
  tableName?: string;
  screenId?: number | string;
}

// 선택 상태
export interface SelectionState {
  itemCode: string | null;
  itemName: string | null;
  routingVersionId: string | null;
  routingVersionName: string | null;
  routingDetailId: string | null;
  processName: string | null;
}
