export type ProcessModuleKind = 'holder' | 'wheel';

export type ProcessSourceKind = 'HOLDER_SUMMARY' | 'WHEEL_SUMMARY';

export type ProcessValidationMode = 'validOnly' | 'allOrNothing';

export type ProcessMaterialRowInput = {
  id?: string;
  lineCode?: string;
  rawMaterialId?: string;
  materialCode?: string;
  materialName?: string;
  materialType?: string;
  length?: number | string | null;
  width?: number | string | null;
  thickness?: number | string | null;
  quantity?: number | string | null;
  noOfStrips?: number | string | null;
  noOfPcsPerStrip?: number | string | null;
  noOfSetsPerSheet?: number | string | null;
  oneSheetWeight?: number | string | null;
  pcsWeightGram?: number | string | null;
  weightGram?: number | string | null;
  noOfPcsPerKg?: number | string | null;
  standardPrice?: number | string | null;
  oneSheetRate?: number | string | null;
  weight?: number | string | null;
  piecesPerKgOrMeter?: number | string | null;
  cavityCount?: number | string | null;
  materialTotal?: number | string | null;
  importedMaterialTotal?: number | string | null;
  sourceData?: Record<string, unknown>;
};

export type ProcessMachineRowInput = {
  id?: string;
  lineCode?: string;
  processName?: string;
  machineId?: string;
  machineName?: string | null;
  machineMetric?: string | null;
  machineHourRate?: number | string | null;
  labourCostPerHour?: number | string | null;
  productionPerHour?: number | string | null;
  productionCostPerPiece?: number | string | null;
  quantity?: number | string | null;
  oneStripCuttingCharge?: number | string | null;
  onePieceCuttingCharge?: number | string | null;
  galvanizingPerKg?: number | string | null;
  galvanizingPerPiece?: number | string | null;
  total?: number | string | null;
  sourceData?: Record<string, unknown>;
};

export type ProcessCoatingRowInput = {
  id?: string;
  lineCode?: string;
  coatingType?: string;
  mode?: 'Per KG' | 'Per PCS' | string;
  unitPrice?: number | string | null;
  quantity?: number | string | null;
  weightKg?: number | string | null;
  weightGram?: number | string | null;
  total?: number | string | null;
  sourceData?: Record<string, unknown>;
};

export type ProcessRecordWriteDto = {
  id?: string;
  processCode?: string;
  processName?: string;
  processType?: string;
  inch?: string;
  finishVariant?: string;
  plateCodes?: string[];
  materialRows?: ProcessMaterialRowInput[];
  machineRows?: ProcessMachineRowInput[];
  coatingRows?: ProcessCoatingRowInput[];
  status?: string;
  createdBy?: string;
  sourceFile?: string;
  materialTotal?: number;
  processTotal?: number;
  coatingTotal?: number;
  totalAll?: number;
};

export type CalculatedMaterialRow = ProcessMaterialRowInput & {
  materialName: string;
  materialType: string;
  lineCode: string;
  materialTotal: number;
};

export type CalculatedMachineRow = ProcessMachineRowInput & {
  processName: string;
  lineCode: string;
  total: number;
  productionCostPerPiece: number;
};

export type CalculatedCoatingRow = ProcessCoatingRowInput & {
  coatingType: string;
  mode: 'Per KG' | 'Per PCS';
  total: number;
};

export type CalculatedProcessRecord = {
  kind: ProcessModuleKind;
  processCode: string;
  processName: string;
  processType: string;
  inch: string;
  finishVariant: string;
  plateCodes: string[];
  materialRows: CalculatedMaterialRow[];
  machineRows: CalculatedMachineRow[];
  coatingRows: CalculatedCoatingRow[];
  materialTotal: number;
  processTotal: number;
  coatingTotal: number;
  totalAll: number;
};

export type ProcessImportPreviewRow = {
  rowNumber: number;
  code: string;
  name: string;
  finishVariant: string;
  plateCodes: string[];
  materialRows: number;
  machineRows: number;
  coatingRows: number;
  valid: boolean;
  errors: string[];
  payload: ProcessRecordWriteDto;
};
