import type { Product } from './product'

export interface InventoryListItem {
  stockItemId: string
  productName: string
  locationName: string
  locationCode: string | null
  qtyOnHand: number
  avgUnitCost: number
}

export interface InventoryDashboardSummary {
  skuCount: number
  locationCount: number
  qtyOnHand: number
  inventoryValue: number
  cogsTotal: number
}

export interface InventoryCogsRow {
  stockItemId: string
  productName: string
  qtySold: number
  cogsAmount: number
  lastSoldAt: string | null
}

export interface InventoryReport {
  summary: InventoryDashboardSummary
  valuationRows: InventoryListItem[]
  cogsRows: InventoryCogsRow[]
}

export interface ProductInventoryLocation {
  locationId: string
  locationName: string
  locationCode: string | null
  qtyOnHand: number
}

export interface ProductInventoryMovement {
  id: string
  kind: string
  qtyDelta: number
  unitCost: number | null
  occurredAt: string
  locationId: string
  locationName: string
  locationCode: string | null
  holderRef: string | null
}

export interface ProductInventorySummary {
  qtyOnHand: number
  inventoryValue: number
  locationCount: number
  lastMovementAt: string | null
}

export interface ProductInventoryHistory {
  product: Product
  summary: ProductInventorySummary
  locations: ProductInventoryLocation[]
  movements: ProductInventoryMovement[]
}

export interface InventoryLocation {
  id: string
  name: string
  code: string | null
  isDefault: boolean
  isActive: boolean
}

export interface InventoryReportRow {
  productId: string
  productName: string
  stockItemId: string
  locationId: string
  locationName: string | null
  locationCode: string | null
  category: string | null
  unit: string
  quantityOnHand: number
  avgUnitCost: number
  valuationAmount: number
  cogsAmount: number
}

export interface InventoryReportSummary {
  valuationAmount: number
  cogsAmount: number
  itemCount: number
  quantityOnHand: number
}

export interface InventoryReportResponse {
  asOf: string
  from: string
  to: string
  summary: InventoryReportSummary
  rows: InventoryReportRow[]
}
