// POP 생산실적관리 타입 정의

export interface Process {
  id: string;
  name: string;
  code: string;
}

export interface Equipment {
  id: string;
  name: string;
  processIds: string[];
  processNames: string[];
  status: "running" | "idle" | "maintenance";
}

export interface ProcessFlowStep {
  id: string;
  name: string;
  status: "pending" | "current" | "completed";
  isReturnTarget?: boolean;
}

export interface WorkOrder {
  id: string;
  itemCode: string;
  itemName: string;
  spec: string;
  orderQuantity: number;
  producedQuantity: number;
  status: "waiting" | "in-progress" | "completed";
  process: string;
  processName: string;
  equipment: string | null;
  equipmentName: string | null;
  startDate: string;
  dueDate: string;
  completedDate?: string;
  priority: "high" | "medium" | "normal" | "low";
  accepted: boolean;
  processFlow: ProcessFlowStep[];
  currentProcessIndex: number;
  // 리턴 관련
  isReturn?: boolean;
  returnReason?: string;
  returnFromProcess?: string;
  returnFromProcessName?: string;
  // 분할접수 관련
  acceptedQuantity?: number;
  remainingQuantity?: number;
  isPartialAccept?: boolean;
}

export interface WorkStepTemplate {
  id: number;
  name: string;
  type:
    | "equipment-check"
    | "material-check"
    | "setup"
    | "work"
    | "inspection"
    | "record"
    | "preparation";
  description: string;
}

export interface WorkStep extends WorkStepTemplate {
  status: "pending" | "in-progress" | "completed";
  startTime: Date | null;
  endTime: Date | null;
  data: Record<string, any>;
}

export type StatusType = "waiting" | "pending-accept" | "in-progress" | "completed";

export type ProductionType = "work-order" | "material";

export interface AppState {
  currentStatus: StatusType;
  selectedEquipment: Equipment | null;
  selectedProcess: Process | null;
  selectedWorkOrder: WorkOrder | null;
  showMyWorkOnly: boolean;
  currentWorkSteps: WorkStep[];
  currentStepIndex: number;
  currentProductionType: ProductionType;
  selectionMode: "single" | "multi";
  completionAction: "close" | "stay";
  acceptTargetWorkOrder: WorkOrder | null;
  acceptQuantity: number;
  theme: "dark" | "light";
}

export interface ModalState {
  equipment: boolean;
  process: boolean;
  accept: boolean;
  settings: boolean;
}

export interface PanelState {
  production: boolean;
}
