import type {
  WorkCenter,
  Routing,
  RoutingOperation,
  BillOfMaterial,
  BillOfMaterialLine,
  ProductionOrder,
  ProductionOrderMaterialRequirement,
  ProductionOrderBomSnapshot,
  ProductionOrderRoutingSnapshot,
  ProductionOrderCostBaseline,
  WorkOrder,
  WorkOrderExecutionEvent,
  ManufacturingCostSummary,
  ManufacturingCostLine,
  CostVarianceLine,
  ManufacturingCostSettlementRecord,
  Schema,
} from "../lib/types";
import type { Item, Site } from "./moduleMocks";

export const baseItem = {
  id: "item-1",
  sku: "ITEM-001",
  name: "Base Item",
  barcode: null,
  unitId: "unit-1",
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Item;

export const baseSite = {
  id: "site-1",
  name: "Main Site",
  type: "WAREHOUSE",
  status: "ACTIVE",
  companyId: "company-1",
  street: "123 Main St",
  city: "New York",
  state: "NY",
  postalCode: "10001",
  country: "US",
  timezone: "America/New_York",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Site;

// WorkCenter fixtures
export const baseDraftWorkCenter = {
  id: "work-center-1",
  code: "WC-001",
  companyId: "company-1",
  siteId: "site-1",
  status: "DRAFT",
  capacityAssumptions: 100,
  laborRate: 25.0,
  machineRate: 50.0,
  calendarReference: "cal-standard",
  overheadAbsorptionMethod: null,
  overheadAbsorptionCurrency: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies WorkCenter<Schema>;

export const baseActiveWorkCenter = {
  ...baseDraftWorkCenter,
  id: "work-center-2",
  code: "WC-002",
  status: "ACTIVE",
} as const satisfies WorkCenter<Schema>;

export const baseInactiveWorkCenter = {
  ...baseDraftWorkCenter,
  id: "work-center-3",
  code: "WC-003",
  status: "INACTIVE",
} as const satisfies WorkCenter<Schema>;

// Routing fixtures
export const baseDraftRouting = {
  id: "routing-1",
  parentItemId: "item-1",
  companyId: "company-1",
  siteId: null,
  revisionNumber: "R1",
  status: "DRAFT",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Routing<Schema>;

export const baseActiveRouting = {
  ...baseDraftRouting,
  id: "routing-2",
  revisionNumber: "R2",
  status: "ACTIVE",
} as const satisfies Routing<Schema>;

export const baseInactiveRouting = {
  ...baseDraftRouting,
  id: "routing-3",
  revisionNumber: "R3",
  status: "INACTIVE",
} as const satisfies Routing<Schema>;

// RoutingOperation fixtures
export const baseRoutingOperation = {
  id: "operation-1",
  routingId: "routing-1",
  sequenceNumber: 10,
  operationDescription: "Assembly step",
  workCenterId: "work-center-2",
  standardSetupTime: 30,
  standardRunTime: 60,
  operatorInstructions: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies RoutingOperation<Schema>;

export const baseRoutingOperation2 = {
  ...baseRoutingOperation,
  id: "operation-2",
  sequenceNumber: 20,
  operationDescription: "Quality check",
  standardSetupTime: 10,
  standardRunTime: 15,
} as const satisfies RoutingOperation<Schema>;

// BillOfMaterial fixtures
export const baseDraftBom = {
  id: "bom-1",
  parentItemId: "item-1",
  companyId: "company-1",
  siteId: null,
  bomType: "MANUFACTURE",
  effectivityStartDate: null,
  effectivityEndDate: null,
  defaultSelection: true,
  revisionNumber: "V1",
  status: "DRAFT",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies BillOfMaterial<Schema>;

export const baseActiveBom = {
  ...baseDraftBom,
  id: "bom-2",
  revisionNumber: "V2",
  status: "ACTIVE",
} as const satisfies BillOfMaterial<Schema>;

export const baseInactiveBom = {
  ...baseDraftBom,
  id: "bom-3",
  revisionNumber: "V3",
  status: "INACTIVE",
} as const satisfies BillOfMaterial<Schema>;

// BillOfMaterialLine fixtures
export const baseBomLine = {
  id: "bom-line-1",
  billOfMaterialId: "bom-1",
  itemId: "item-2",
  requiredQuantity: 2.0,
  unitOfMeasure: "EA",
  scrapAssumption: 5.0,
  isSubassembly: false,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies BillOfMaterialLine<Schema>;

export const baseBomLine2 = {
  ...baseBomLine,
  id: "bom-line-2",
  itemId: "item-3",
  requiredQuantity: 1.0,
  scrapAssumption: null,
} as const satisfies BillOfMaterialLine<Schema>;

// ProductionOrder fixtures
export const baseDraftProductionOrder = {
  id: "production-order-1",
  orderedItemId: "item-1",
  companyId: "company-1",
  siteId: "site-1",
  plannedQuantity: 100,
  plannedStartDate: new Date("2024-03-01T00:00:00.000Z"),
  plannedEndDate: new Date("2024-03-15T00:00:00.000Z"),
  selectedBomVersionId: null,
  selectedRoutingRevisionId: null,
  status: "DRAFT",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ProductionOrder<Schema>;

export const baseReleasedProductionOrder = {
  ...baseDraftProductionOrder,
  id: "production-order-2",
  selectedBomVersionId: "bom-2",
  selectedRoutingRevisionId: "routing-2",
  status: "RELEASED",
} as const satisfies ProductionOrder<Schema>;

export const baseInProgressProductionOrder = {
  ...baseReleasedProductionOrder,
  id: "production-order-3",
  status: "IN_PROGRESS",
} as const satisfies ProductionOrder<Schema>;

export const baseCompletedProductionOrder = {
  ...baseReleasedProductionOrder,
  id: "production-order-4",
  status: "COMPLETED",
} as const satisfies ProductionOrder<Schema>;

export const baseTechCompleteProductionOrder = {
  ...baseReleasedProductionOrder,
  id: "production-order-5",
  status: "TECHNICALLY_COMPLETE",
} as const satisfies ProductionOrder<Schema>;

export const baseClosedProductionOrder = {
  ...baseReleasedProductionOrder,
  id: "production-order-6",
  status: "CLOSED",
} as const satisfies ProductionOrder<Schema>;

export const baseCancelledProductionOrder = {
  ...baseDraftProductionOrder,
  id: "production-order-7",
  status: "CANCELLED",
} as const satisfies ProductionOrder<Schema>;

// ProductionOrderMaterialRequirement fixtures
export const baseMaterialRequirement = {
  id: "material-req-1",
  productionOrderId: "production-order-2",
  itemId: "item-2",
  requiredQuantity: 200,
  unitOfMeasure: "EA",
  plannedUnitCost: 10.0,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ProductionOrderMaterialRequirement<Schema>;

// ProductionOrderBomSnapshot fixtures
export const baseBomSnapshot = {
  id: "bom-snapshot-1",
  productionOrderId: "production-order-2",
  parentItemId: "item-1",
  bomType: "MANUFACTURE",
  snapshotData: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ProductionOrderBomSnapshot<Schema>;

// ProductionOrderRoutingSnapshot fixtures
export const baseRoutingSnapshot = {
  id: "routing-snapshot-1",
  productionOrderId: "production-order-2",
  routingId: "routing-2",
  snapshotData: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ProductionOrderRoutingSnapshot<Schema>;

// ProductionOrderCostBaseline fixtures
export const baseCostBaseline = {
  id: "cost-baseline-1",
  productionOrderId: "production-order-2",
  plannedMaterialCost: 2000,
  plannedLaborCost: 500,
  plannedMachineCost: 1000,
  plannedOverheadCost: 300,
  currencyCode: "USD",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ProductionOrderCostBaseline<Schema>;

// WorkOrder fixtures
export const basePendingWorkOrder = {
  id: "work-order-1",
  productionOrderId: "production-order-2",
  routingOperationSequenceNumber: 10,
  workCenterId: "work-center-2",
  plannedQuantity: 100,
  completedQuantity: 0,
  scrapQuantity: 0,
  actualSetupTime: 0,
  actualRunTime: 0,
  actualStartDate: null,
  pauseReason: null,
  executionNotes: null,
  status: "PENDING",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies WorkOrder<Schema>;

export const baseInProgressWorkOrder = {
  ...basePendingWorkOrder,
  id: "work-order-2",
  status: "IN_PROGRESS",
  actualStartDate: new Date("2024-03-01T08:00:00.000Z"),
  completedQuantity: 50,
  actualSetupTime: 30,
  actualRunTime: 120,
} as const satisfies WorkOrder<Schema>;

export const basePausedWorkOrder = {
  ...baseInProgressWorkOrder,
  id: "work-order-3",
  status: "PAUSED",
  pauseReason: "Machine maintenance",
} as const satisfies WorkOrder<Schema>;

export const baseCompleteWorkOrder = {
  ...baseInProgressWorkOrder,
  id: "work-order-4",
  status: "COMPLETE",
  completedQuantity: 100,
  actualRunTime: 240,
} as const satisfies WorkOrder<Schema>;

export const baseCancelledWorkOrder = {
  ...basePendingWorkOrder,
  id: "work-order-5",
  status: "CANCELLED",
} as const satisfies WorkOrder<Schema>;

// WorkOrderExecutionEvent fixtures
export const baseStartedEvent = {
  id: "event-1",
  workOrderId: "work-order-2",
  eventType: "STARTED",
  timestamp: new Date("2024-03-01T08:00:00.000Z"),
  quantity: null,
  timeValue: null,
  scrapValue: null,
  notes: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies WorkOrderExecutionEvent<Schema>;

export const baseProgressEvent = {
  ...baseStartedEvent,
  id: "event-2",
  eventType: "PROGRESS_REPORTED",
  timestamp: new Date("2024-03-01T10:00:00.000Z"),
  quantity: 25,
  timeValue: 60,
  scrapValue: 2,
} as const satisfies WorkOrderExecutionEvent<Schema>;

// ManufacturingCostSummary fixtures
export const baseCollectingCostSummary = {
  id: "cost-summary-1",
  productionOrderId: "production-order-2",
  plannedMaterialCost: 2000,
  plannedLaborCost: 500,
  plannedMachineCost: 1000,
  plannedOverheadCost: 300,
  actualMaterialCost: 0,
  actualLaborCost: 0,
  actualMachineCost: 0,
  actualOverheadCost: 0,
  currencyCode: "USD",
  reviewedDate: null,
  reviewerNotes: null,
  status: "COLLECTING",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ManufacturingCostSummary<Schema>;

export const basePendingReviewCostSummary = {
  ...baseCollectingCostSummary,
  id: "cost-summary-2",
  actualMaterialCost: 2100,
  actualLaborCost: 480,
  actualMachineCost: 1050,
  actualOverheadCost: 50,
  status: "PENDING_VARIANCE_REVIEW",
} as const satisfies ManufacturingCostSummary<Schema>;

export const baseReviewedCostSummary = {
  ...basePendingReviewCostSummary,
  id: "cost-summary-3",
  status: "VARIANCE_REVIEWED",
  reviewedDate: new Date("2024-04-01T00:00:00.000Z"),
  reviewerNotes: "Variances within acceptable range",
} as const satisfies ManufacturingCostSummary<Schema>;

export const baseSettledCostSummary = {
  ...baseReviewedCostSummary,
  id: "cost-summary-4",
  status: "SETTLED",
} as const satisfies ManufacturingCostSummary<Schema>;

// ManufacturingCostLine fixtures
export const baseCostLine = {
  id: "cost-line-1",
  costSummaryId: "cost-summary-1",
  costType: "MATERIAL",
  plannedAmount: 2000,
  actualAmount: 0,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ManufacturingCostLine<Schema>;

// CostVarianceLine fixtures
export const baseVarianceLine = {
  id: "variance-line-1",
  costSummaryId: "cost-summary-3",
  varianceType: "MATERIAL_PRICE",
  amount: 100,
  accountReference: "acct-5001",
  variancePercentage: 5.0,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies CostVarianceLine<Schema>;

// ManufacturingCostSettlementRecord fixtures
export const baseSettlementRecord = {
  id: "settlement-1",
  costSummaryId: "cost-summary-4",
  settlementDate: new Date("2024-04-15T00:00:00.000Z"),
  settlementReference: "SETTLE-2024-001",
  acknowledgedDate: new Date("2024-04-15T00:00:00.000Z"),
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ManufacturingCostSettlementRecord<Schema>;
