// 생산지시 상태 (프론트 탭용)
export type ProductionStatus = 'waiting' | 'in_production' | 'completed';

// API 응답 타입 (snake_case)
export interface ApiProductionOrder {
  id: number;
  order_no: string;
  site_name: string;
  client_name: string;
  quantity: number;
  node_count: number;
  delivery_date: string | null;
  status_code: string;
  production_ordered_at: string | null;
  production_status: ProductionStatus;
  work_orders_count: number;
  nodes_count: number;
  work_order_progress: {
    total: number;
    completed: number;
    in_progress: number;
  };
  client?: {
    id: number;
    name: string;
  };
}

// 프론트 타입 (camelCase)
export interface ProductionOrder {
  id: string;
  orderNumber: string;
  siteName: string;
  clientName: string;
  quantity: number;
  nodeCount: number;
  deliveryDate: string;
  productionOrderedAt: string;
  productionStatus: ProductionStatus;
  workOrderCount: number;
  workOrderProgress: {
    total: number;
    completed: number;
    inProgress: number;
  };
}

// 생산지시 통계
export interface ProductionOrderStats {
  total: number;
  waiting: number;
  in_production: number;
  completed: number;
}

// 생산지시 상세 API 응답
export interface ApiProductionOrderDetail {
  order: ApiProductionOrder;
  production_ordered_at: string | null;
  production_status: ProductionStatus;
  node_count: number;
  work_order_progress: {
    total: number;
    completed: number;
    in_progress: number;
  };
  work_orders: ApiProductionWorkOrder[];
  bom_process_groups: ApiBomProcessGroup[];
}

// 상세 내 작업지시 정보
export interface ApiProductionWorkOrder {
  id: number;
  work_order_no: string;
  process_name: string;
  quantity: number;
  status: string;
  assignees: string[];
}

// BOM 공정 분류
export interface ApiBomProcessGroup {
  process_name: string;
  size_spec?: string;
  items: ApiBomItem[];
}

export interface ApiBomItem {
  id: number | null;
  item_code: string;
  item_name: string;
  spec: string;
  unit: string;
  quantity: number;
  unit_price: number;
  total_price: number;
  node_name: string;
}

// 프론트 상세 타입
export interface ProductionOrderDetail extends ProductionOrder {
  workOrders: ProductionWorkOrder[];
  bomProcessGroups: BomProcessGroup[];
}

export interface ProductionWorkOrder {
  id: number;
  workOrderNo: string;
  processName: string;
  quantity: number;
  status: string;
  assignees: string[];
}

export interface BomProcessGroup {
  processName: string;
  sizeSpec?: string;
  items: BomItem[];
}

export interface BomItem {
  id: number | null;
  itemCode: string;
  itemName: string;
  spec: string;
  unit: string;
  quantity: number;
  unitPrice: number;
  totalPrice: number;
  nodeName: string;
}

// 조회 파라미터
export interface ProductionOrderListParams {
  search?: string;
  productionStatus?: ProductionStatus;
  sortBy?: string;
  sortDir?: 'asc' | 'desc';
  page?: number;
  perPage?: number;
}
