import type {
  Warehouse,
  StorageLocation,
  ValuationPolicy,
  StockLevel,
  StockMovement,
  StockMoveLine,
  Lot,
  LotStockLevel,
  SerialNumber,
  InventoryCount,
  InventoryCountLine,
  InventoryAdjustment,
  ItemValuation,
  CostLayer,
  Schema,
} from "../lib/types";

// Warehouse fixtures
export const baseActiveWarehouse = {
  id: "warehouse-1",
  name: "Main Warehouse",
  siteId: "site-1",
  storageCondition: null,
  capacity: null,
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Warehouse<Schema>;

export const baseInactiveWarehouse = {
  id: "warehouse-2",
  name: "Closed Warehouse",
  siteId: "site-1",
  storageCondition: "cold",
  capacity: 5000,
  status: "INACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Warehouse<Schema>;

// StorageLocation fixtures
export const baseZone = {
  id: "location-1",
  name: "Zone A",
  code: "ZA",
  warehouseId: "warehouse-1",
  parentId: null,
  locationType: "zone",
  storageCondition: null,
  capacity: null,
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StorageLocation<Schema>;

export const baseBin = {
  id: "location-2",
  name: "Bin A-1",
  code: "BA1",
  warehouseId: "warehouse-1",
  parentId: "location-1",
  locationType: "bin",
  storageCondition: null,
  capacity: null,
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StorageLocation<Schema>;

export const baseInactiveLocation = {
  id: "location-3",
  name: "Inactive Zone",
  code: "IZ",
  warehouseId: "warehouse-1",
  parentId: null,
  locationType: "zone",
  storageCondition: null,
  capacity: null,
  status: "INACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StorageLocation<Schema>;

// ValuationPolicy fixtures
export const baseFifoPolicy = {
  id: "policy-1",
  name: "FIFO Policy",
  costingMethod: "FIFO",
  standardCostRate: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ValuationPolicy<Schema>;

export const baseAvcoPolicy = {
  id: "policy-2",
  name: "AVCO Policy",
  costingMethod: "AVCO",
  standardCostRate: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ValuationPolicy<Schema>;

export const baseStandardCostPolicy = {
  id: "policy-3",
  name: "Standard Cost Policy",
  costingMethod: "STANDARD_COST",
  standardCostRate: 10.5,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ValuationPolicy<Schema>;

// StockLevel fixtures
export const baseStockLevel = {
  id: "stock-level-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  onHand: 100,
  reserved: 10,
  incoming: 20,
  blocked: 5,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockLevel<Schema>;

export const emptyStockLevel = {
  id: "stock-level-2",
  itemId: "item-2",
  storageLocationId: "location-1",
  onHand: 0,
  reserved: 0,
  incoming: 0,
  blocked: 0,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockLevel<Schema>;

// StockMovement fixtures
export const baseDraftMovement = {
  id: "movement-1",
  movementType: "GOODS_RECEIPT",
  reasonCode: null,
  status: "DRAFT",
  executedAt: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockMovement<Schema>;

export const baseConfirmedMovement = {
  id: "movement-2",
  movementType: "GOODS_RECEIPT",
  reasonCode: null,
  status: "CONFIRMED",
  executedAt: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockMovement<Schema>;

export const baseDoneMovement = {
  id: "movement-3",
  movementType: "GOODS_RECEIPT",
  reasonCode: null,
  status: "DONE",
  executedAt: new Date("2024-01-02T00:00:00.000Z"),
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockMovement<Schema>;

export const baseCancelledMovement = {
  id: "movement-4",
  movementType: "GOODS_RECEIPT",
  reasonCode: null,
  status: "CANCELLED",
  executedAt: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockMovement<Schema>;

// StockMoveLine fixtures
export const baseMoveLine = {
  id: "move-line-1",
  stockMovementId: "movement-1",
  itemId: "item-1",
  quantity: 50,
  sourceLocationId: null,
  destinationLocationId: "location-1",
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockMoveLine<Schema>;

// Lot fixtures
export const baseActiveLot = {
  id: "lot-1",
  lotNumber: "LOT-001",
  itemId: "item-1",
  manufactureDate: new Date("2024-01-01T00:00:00.000Z"),
  expirationDate: new Date("2025-01-01T00:00:00.000Z"),
  supplierLotReference: "SUP-LOT-001",
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Lot<Schema>;

export const baseFullyConsumedLot = {
  id: "lot-2",
  lotNumber: "LOT-002",
  itemId: "item-1",
  manufactureDate: new Date("2023-06-01T00:00:00.000Z"),
  expirationDate: new Date("2024-06-01T00:00:00.000Z"),
  supplierLotReference: null,
  status: "FULLY_CONSUMED",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies Lot<Schema>;

// LotStockLevel fixtures
export const baseLotStockLevel = {
  id: "lot-stock-1",
  lotId: "lot-1",
  storageLocationId: "location-1",
  onHand: 50,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies LotStockLevel<Schema>;

// SerialNumber fixtures
export const baseAvailableSerial = {
  id: "serial-1",
  serialNumber: "SN-001",
  itemId: "item-1",
  storageLocationId: "location-1",
  status: "AVAILABLE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies SerialNumber<Schema>;

export const baseIssuedSerial = {
  id: "serial-2",
  serialNumber: "SN-002",
  itemId: "item-1",
  storageLocationId: "location-1",
  status: "ISSUED",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies SerialNumber<Schema>;

// InventoryCount fixtures
export const basePlannedCount = {
  id: "count-1",
  countType: "FULL",
  warehouseId: "warehouse-1",
  storageLocationId: null,
  plannedDate: new Date("2024-02-01T00:00:00.000Z"),
  status: "PLANNED",
  isFrozen: false,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryCount<Schema>;

export const baseInProgressCount = {
  id: "count-2",
  countType: "FULL",
  warehouseId: "warehouse-1",
  storageLocationId: null,
  plannedDate: new Date("2024-02-01T00:00:00.000Z"),
  status: "IN_PROGRESS",
  isFrozen: true,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryCount<Schema>;

export const baseCompletedCount = {
  id: "count-3",
  countType: "FULL",
  warehouseId: "warehouse-1",
  storageLocationId: null,
  plannedDate: new Date("2024-02-01T00:00:00.000Z"),
  status: "COMPLETED",
  isFrozen: false,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryCount<Schema>;

// InventoryCountLine fixtures
export const basePendingCountLine = {
  id: "count-line-1",
  inventoryCountId: "count-2",
  itemId: "item-1",
  storageLocationId: "location-1",
  systemQuantity: 100,
  countedQuantity: 98,
  variance: -2,
  status: "PENDING",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryCountLine<Schema>;

export const baseApprovedCountLine = {
  id: "count-line-2",
  inventoryCountId: "count-2",
  itemId: "item-2",
  storageLocationId: "location-1",
  systemQuantity: 50,
  countedQuantity: 50,
  variance: 0,
  status: "APPROVED",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryCountLine<Schema>;

// InventoryAdjustment fixtures
export const baseDraftAdjustment = {
  id: "adjustment-1",
  adjustmentType: "CORRECTION",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantityDelta: -5,
  reasonCode: "damage",
  status: "DRAFT",
  inventoryCountId: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryAdjustment<Schema>;

export const basePendingApprovalAdjustment = {
  id: "adjustment-2",
  adjustmentType: "CORRECTION",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantityDelta: -10,
  reasonCode: "count-variance",
  status: "PENDING_APPROVAL",
  inventoryCountId: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryAdjustment<Schema>;

export const baseApprovedAdjustment = {
  id: "adjustment-3",
  adjustmentType: "CORRECTION",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantityDelta: 5,
  reasonCode: "receiving-error",
  status: "APPROVED",
  inventoryCountId: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryAdjustment<Schema>;

export const baseRejectedAdjustment = {
  id: "adjustment-4",
  adjustmentType: "CORRECTION",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantityDelta: -20,
  reasonCode: "theft",
  status: "REJECTED",
  inventoryCountId: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryAdjustment<Schema>;

export const baseConfirmedAdjustment = {
  id: "adjustment-5",
  adjustmentType: "SCRAP",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantityDelta: -3,
  reasonCode: "expired",
  status: "CONFIRMED",
  inventoryCountId: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies InventoryAdjustment<Schema>;

// ItemValuation fixtures
export const baseItemValuation = {
  id: "valuation-1",
  itemId: "item-1",
  valuationPolicyId: "policy-1",
  totalQuantity: 100,
  totalValue: 1000,
  costPerUnit: 10,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies ItemValuation<Schema>;

// CostLayer fixtures
export const baseCostLayer = {
  id: "cost-layer-1",
  itemId: "item-1",
  valuationPolicyId: "policy-1",
  stockMovementId: "movement-3",
  quantity: 100,
  unitCost: 10,
  remainingQuantity: 80,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies CostLayer<Schema>;
