export type MasterDataIssueScope = "BOM" | "BOM_MATERIAL" | "ITEM";

export type MasterDataIssueCode =
  | "MISSING_BOM_CODE"
  | "MISSING_BOM_NAME"
  | "MISSING_ITEM"
  | "MISSING_BASE_UOM"
  | "MISSING_SALES_UOM"
  | "MISSING_STOCK_UOM"
  | "MISSING_PICKING_UOM"
  | "MISSING_PURCHASE_UOM"
  | "DELETED_BASE_UOM"
  | "DELETED_SALES_UOM"
  | "DELETED_STOCK_UOM"
  | "DELETED_PURCHASE_UOM"
  | "MISSING_BASE_UOM_CONVERSION"
  | "MISSING_SALES_UOM_CONVERSION"
  | "MISSING_STOCK_UOM_CONVERSION"
  | "MISSING_PICKING_UOM_CONVERSION"
  | "MISSING_PURCHASE_UOM_CONVERSION"
  | "MISSING_UOM_CONVERSION"
  | "MISSING_STOCK_UOM_CONVERSION"
  | "MULTIPLE_BASE_UOM"
  | "MULTIPLE_SALES_UOM"
  | "MULTIPLE_STOCK_UOM"
  | "MULTIPLE_PICKING_UOM"
  | "MULTIPLE_PURCHASE_UOM"
  | "BOM_OUTPUT_UOM_MISMATCH_SALES"
  | "BOM_OUTPUT_UOM_TEXT_DRIFT"
  | "BOM_MATERIAL_MISSING_ITEM"
  | "BOM_MATERIAL_SALES_UOM_MISMATCH"
  | "BOM_MATERIAL_BASE_UOM_MISMATCH"
  | "BOM_MATERIAL_STOCK_UOM_MISMATCH"
  | "BOM_MATERIAL_UOM_FK_INVALID";

export interface MasterDataIssue {
  scope: MasterDataIssueScope;
  bomId: number | null;
  bomCode: string | null;
  bomName: string | null;
  bomMaterialId: number | null;
  itemId: number | null;
  itemCode: string | null;
  itemName: string | null;
  description: string | null;
  issueCode: MasterDataIssueCode | string;
  expectedValue: string | null;
  actualValue: string | null;
  baseUnitValue?: string | null;
  stockUnitValue?: string | null;
  purchaseUnitValue?: string | null;
  salesUnitValue?: string | null;
  baseUnitCorrect?: boolean | null;
  stockUnitCorrect?: boolean | null;
  purchaseUnitCorrect?: boolean | null;
  salesUnitCorrect?: boolean | null;
  baseUnitModifiedAt?: string | null;
  stockUnitModifiedAt?: string | null;
  purchaseUnitModifiedAt?: string | null;
  salesUnitModifiedAt?: string | null;
  baseUnitStatus?: "OK" | "MISSING" | "DELETED" | string | null;
  stockUnitStatus?: "OK" | "MISSING" | "DELETED" | string | null;
  purchaseUnitStatus?: "OK" | "MISSING" | "DELETED" | string | null;
  salesUnitStatus?: "OK" | "MISSING" | "DELETED" | string | null;
}

export type ItemUnitStatus = "OK" | "MISSING" | "DELETED";

export interface MasterDataIssueSummaryTiming {
  totalMs: number;
  loadActiveUomsMs: number;
  loadDeletedUomsMs: number;
  loadMaterialsMs: number;
  buildUomCacheMs: number;
  loadBomsMs: number;
  scanBomTabMs: number;
  loadItemsMs: number;
  scanItemTabMs: number;
}

export interface MasterDataIssueSummary {
  bomGroupCount: number;
  itemGroupCount: number;
  totalGroupCount: number;
  /** Set when requesting summary with {@code includeTiming=true}. */
  timing?: MasterDataIssueSummaryTiming | null;
}
