import { ApiError, apiRequest } from '@/api/http' import type { ApiFirstLegStatus, MerchantFirstLegOrderDetail, PageResult } from '@/modules/first-leg/api/firstLeg' export type ApiUnifiedOrderMainStatus = | 'PENDING_REVIEW' | 'WAIT_MEASURE' | 'WAIT_SPLIT' | 'LOADING' | 'LOADED' | 'DELIVERED' export interface MerchantUnifiedMeasurementSummary { reviewStatus: string | null actualGrossWeightKg: number | null actualVolumeCbm: number | null chargeableWeightKg: number | null completedAt: string | null } export interface MerchantUnifiedPreloadSummary { status: string version: number itemCount: number updatedAt: string | null } export interface MerchantUnifiedLoadingSummary { status: string loadingVersion: number pickingVersion: number expectedCount: number | null pickedCount: number | null evidenceCount: number | null sealNo: string | null updatedAt: string | null } export interface MerchantUnifiedDeliverySummary { status: string completedAt: string | null trackingNo: string | null } export interface MerchantUnifiedTransportSummary { loadingStatus: string | null containerNo: string | null cabinetNo: string | null vesselName: string | null voyageNo: string | null sailingAt: string | null portArrivalAt: string | null } export interface MerchantUnifiedOrderRow { orderId: number | string tenantId: number | string orderNo: string | null mainStatus: ApiUnifiedOrderMainStatus nextAction: string | null internalOrderStatus: ApiFirstLegStatus | null customerId: number | string | null customerName: string channelName: string | null receivingWarehouseId: number | string | null receivingWarehouseName: string | null destinationWarehouseId: number | string | null destinationWarehouseName: string | null inboundId: number | string | null inboundVersion: number | null inboundCode: string | null expectedShipDate: string | null totalPackageCount: number | null actualGrossWeightKg: number | null actualVolumeCbm: number | null skuNos?: string[] | null expressCompany?: string | null totalNetWeightKg?: number | null totalQuantity?: number | null chargeableVolumeCbm?: number | null shipmentId?: string | null referenceId?: string | null inboundedAt?: string | null businessDate?: string | null measurement: MerchantUnifiedMeasurementSummary | null preload: MerchantUnifiedPreloadSummary | null loading: MerchantUnifiedLoadingSummary | null delivery: MerchantUnifiedDeliverySummary | null transport: MerchantUnifiedTransportSummary | null customerRemark: string | null createdAt: string updatedAt: string } export interface MerchantUnifiedTimelineEvent { source: string eventType: string mainStatus: ApiUnifiedOrderMainStatus | null action: string | null remark: string | null operatorId: number | string | null operatorName: string | null occurredAt: string | null } export interface MerchantUnifiedCustomNode { id: number | string name: string nodeType: string sortOrder: number customerVisible: boolean plannedAt: string | null completedAt: string | null operatorName: string | null remark: string | null attachmentIds: Array } export interface MerchantUnifiedOrderDetail { summary: MerchantUnifiedOrderRow order: MerchantFirstLegOrderDetail timeline: MerchantUnifiedTimelineEvent[] // C02 does not return custom nodes yet. Optionality keeps the client forward-compatible without inventing data. customNodes?: MerchantUnifiedCustomNode[] } export interface MerchantUnifiedOrderQuery { keyword?: string orderNo?: string mainStatus?: ApiUnifiedOrderMainStatus receivingWarehouseId?: number | string destinationWarehouseId?: number | string createdFrom?: string createdTo?: string page?: number size?: number } const unifiedOrderBaseUrl = '/merchant/v1/orders' export function getMerchantUnifiedOrders(params: MerchantUnifiedOrderQuery = {}) { const { page, size, ...filters } = params return apiRequest>({ method: 'GET', url: unifiedOrderBaseUrl, params: { page: page ?? 1, size: size ?? 200, ...filters }, }) } export function getMerchantUnifiedOrder(orderId: number | string) { return apiRequest({ method: 'GET', url: `${unifiedOrderBaseUrl}/${orderId}`, }) } export function isUnifiedOrderQueryUnavailable(error: unknown) { return error instanceof ApiError && (error.status === 404 || error.code === 'A0404') }