import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' import { normalizeOverseasPage, type OverseasPagePayload } from './lastMileOrders' export interface InventoryBalanceDto { id: string customerId: string customerName?: string | null overseasWarehouseId: string overseasWarehouseCode?: string | null overseasWarehouseName?: string | null destinationWarehouseId?: string | null destinationWarehouseCode?: string | null destinationWarehouseName?: string | null inboundOrderId: string inboundOrderNo?: string | null inboundCode: string skuCode?: string | null productNameZh?: string | null productNameEn?: string | null totalPackages: number availablePackages: number holdPackages: number allocatedPackages: number pickedPackages: number inTransitPackages: number receivingPackages: number procurementPackages: number updatedAt?: string | null } export interface InventoryDashboardDto { inboundOrderCount: number palletCount: number totalPackages: number availablePackages: number holdPackages: number allocatedPackages: number pickedPackages: number inTransitPackages: number receivingPackages: number procurementPackages: number } export interface InventoryPositionDto { id: string balanceId: string overseasWarehouseId?: string | null destinationWarehouseCode?: string | null inboundOrderId?: string | null inboundOrderNo?: string | null inboundCode?: string | null palletId?: string | null palletNo?: string | null batchNo?: string | null warehouseLocationId?: string | null warehouseLocationCode?: string | null totalPackages: number availablePackages: number holdPackages: number allocatedPackages: number pickedPackages: number receivingPackages: number status?: string | null updatedAt?: string | null } export interface InventoryLedgerDto { id: string customerId: string customerName?: string | null overseasWarehouseId?: string | null destinationWarehouseCode?: string | null inboundOrderId?: string | null inboundOrderNo?: string | null inboundCode?: string | null palletNo?: string | null batchNo?: string | null warehouseLocationCode?: string | null skuCode?: string | null businessType?: string | null businessOrderNo?: string | null outboundOrderNo?: string | null statusFrom?: string | null statusTo?: string | null beforePackages: number deltaPackages: number afterPackages: number operatorId?: string | null remark?: string | null occurredAt?: string | null } export interface InventoryBalanceQuery { page: number size: number customerName?: string overseasWarehouseId?: string overseasWarehouseCode?: string destinationWarehouseCode?: string inboundOrderNo?: string inboundCode?: string businessOrderNo?: string skuCode?: string productName?: string batchNo?: string warehouseLocationCode?: string inventoryStatus?: string } function params(query: InventoryBalanceQuery) { return { ...query } } export async function listInventoryBalances(query: InventoryBalanceQuery) { const response = await http.get>, ApiEnvelope>>( '/platform/v1/last-leg/inventory/balances', { params: params(query) }, ) return normalizeOverseasPage(unwrapApiResponse(response)) } export async function getInventorySummary(query: InventoryBalanceQuery) { const response = await http.get, ApiEnvelope>( '/platform/v1/last-leg/inventory/summary', { params: params({ ...query, page: 1, size: 200 }) }, ) return unwrapApiResponse(response) } export async function listInventoryPositions( balanceId: string, query: { palletNo?: string; batchNo?: string; inventoryStatus?: string } = {}, ) { const response = await http.get, ApiEnvelope>( `/platform/v1/last-leg/inventory/balances/${encodeURIComponent(balanceId)}/positions`, { params: query }, ) return unwrapApiResponse(response) } export interface InventoryLedgerQuery { page: number size: number customerName?: string overseasWarehouseId?: string destinationWarehouseCode?: string businessType?: string businessOrderNo?: string inboundOrderNo?: string inboundCode?: string outboundOrderNo?: string palletNo?: string batchNo?: string skuCode?: string warehouseLocationCode?: string occurredFrom?: string occurredTo?: string } export async function listInventoryLedger(query: InventoryLedgerQuery) { const response = await http.get>, ApiEnvelope>>( '/platform/v1/last-leg/inventory/ledger', { params: { ...query } }, ) return normalizeOverseasPage(unwrapApiResponse(response)) }