import type {
  StorageLocation,
  ValuationPolicy,
  StockLevel,
  Lot,
  LotStockLevel,
  SerialNumber,
  StockAdjustment,
  StockAdjustmentLine,
  ItemValuation,
  CostLayer,
  Schema,
} from "../lib/types";

// Site fixtures (minimal shape for cross-module tests)
export const baseActiveSite = {
  id: "site-1",
  name: "Tokyo DC",
  type: "WAREHOUSE",
  companyId: "company-1",
  street: "1-2-3 Shibuya",
  city: "Tokyo",
  state: "Tokyo",
  postalCode: "150-0002",
  country: "JP",
  timezone: "Asia/Tokyo",
  status: "ACTIVE",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const;

export const baseInactiveSite = {
  ...baseActiveSite,
  id: "site-2",
  name: "Osaka DC",
  status: "INACTIVE",
} as const;

// StorageLocation fixtures
export const baseStorageLocation = {
  id: "location-1",
  name: "Main Shelf",
  code: "MAIN",
  siteId: "site-1",
  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 Area",
  code: "OLD",
  siteId: "site-1",
  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>;

// 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",
  blocked: "0",
  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>;

// 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",
  inventoryLedgerId: "ledger-1",
  quantity: "100",
  unitCost: "10",
  remainingQuantity: "80",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies CostLayer<Schema>;

// StockAdjustment fixtures
export const baseDraftAdjustment = {
  id: "adjustment-1",
  adjustmentType: "CORRECTION",
  status: "DRAFT",
  reasonCode: "inventory-count",
  rejectionReason: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustment<Schema>;

export const baseSubmittedAdjustment = {
  id: "adjustment-2",
  adjustmentType: "CORRECTION",
  status: "SUBMITTED",
  reasonCode: "shrinkage",
  rejectionReason: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustment<Schema>;

export const baseRejectedAdjustment = {
  id: "adjustment-3",
  adjustmentType: "SCRAP",
  status: "REJECTED",
  reasonCode: "expired",
  rejectionReason: "need additional review",
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustment<Schema>;

export const baseConfirmedAdjustment = {
  id: "adjustment-4",
  adjustmentType: "CORRECTION",
  status: "CONFIRMED",
  reasonCode: "shrinkage",
  rejectionReason: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustment<Schema>;

export const baseCancelledAdjustment = {
  id: "adjustment-5",
  adjustmentType: "CORRECTION",
  status: "CANCELLED",
  reasonCode: "entered-in-error",
  rejectionReason: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustment<Schema>;

// StockAdjustmentLine fixtures
export const correctionIncreaseLine = {
  id: "adj-line-1",
  stockAdjustmentId: "adjustment-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantity: "5",
  adjustmentDirection: "INCREASE",
  fromStockCategory: null,
  unitCost: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustmentLine<Schema>;

export const correctionDecreaseLine = {
  id: "adj-line-2",
  stockAdjustmentId: "adjustment-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantity: "5",
  adjustmentDirection: "DECREASE",
  fromStockCategory: null,
  unitCost: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustmentLine<Schema>;

export const scrapAvailableLine = {
  id: "adj-line-3",
  stockAdjustmentId: "adjustment-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantity: "3",
  adjustmentDirection: null,
  fromStockCategory: "AVAILABLE",
  unitCost: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustmentLine<Schema>;

export const scrapBlockedLine = {
  id: "adj-line-4",
  stockAdjustmentId: "adjustment-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantity: "3",
  adjustmentDirection: null,
  fromStockCategory: "BLOCKED",
  unitCost: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustmentLine<Schema>;

export const blockLine = {
  id: "adj-line-5",
  stockAdjustmentId: "adjustment-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantity: "10",
  adjustmentDirection: null,
  fromStockCategory: null,
  unitCost: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustmentLine<Schema>;

export const unblockLine = {
  id: "adj-line-6",
  stockAdjustmentId: "adjustment-1",
  itemId: "item-1",
  storageLocationId: "location-1",
  quantity: "5",
  adjustmentDirection: null,
  fromStockCategory: null,
  unitCost: null,
  lotId: null,
  serialNumberId: null,
  createdAt: new Date("2024-01-01T00:00:00.000Z"),
  updatedAt: null,
} as const satisfies StockAdjustmentLine<Schema>;
