import { overseasHttp } from '@/shared/api/overseasHttp' import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' import type { OverseasPageResult } from './lastMileOrders' export interface DispatchQuery { page: number size: number dispatchNo?: string vehiclePlate?: string status?: string fbaAppointmentNo?: string } export interface DispatchPalletCandidateDto { planId: string planPalletId: string warehousePalletId?: string | null orderId: string customerId?: string | null customerName?: string | null planNo?: string | null orderType?: string | null volumeWeightKg?: number | null containerNo?: string | null appointmentAt?: string | null expectedLoadingAt?: string | null overseasWarehouseId?: string | null overseasWarehouseName?: string | null orderNo?: string | null orderRefs?: string | null inboundCode?: string | null palletNo?: string | null destinationWarehouseId?: string | null destinationWarehouseCode?: string | null destinationWarehouseName?: string | null fbaWarehouseCode?: string | null packageCount?: number | null volumeCbm?: number | null sourceStage?: 'PLAN' | 'RECEIVED' | null cartonMarks?: string | null } export interface DispatchCandidateQuery { planIds?: string orderNo?: string fbaWarehouseCode?: string sourceStage?: 'PLAN' | 'RECEIVED' } export interface PreArrangeDispatchPayload { planPalletIds: string[] route?: string fbaAppointmentNo?: string fbaAppointmentStatus?: string vehicleAppointmentStatus?: string draftToken?: string } export interface DispatchSummaryDto { id: string dispatchNo: string vehiclePlate?: string | null driverName?: string | null driverPhone?: string | null carrierName?: string | null orderNos?: string | null route?: string | null overseasWarehouseId?: string | null overseasWarehouseName?: string | null departAt?: string | null fbaAppointmentNo?: string | null fbaAppointmentStatus?: string | null vehicleAppointmentStatus?: string | null estimatedArrivalAt?: string | null status?: string | null itemCount?: number | null palletCount?: number | null packageCount?: number | null pickedPackageCount?: number | null shippedPackageCount?: number | null remainingPackageCount?: number | null partialCompletionReason?: string | null createdAt?: string | null } export async function listDispatches(query: DispatchQuery) { const response = await overseasHttp.get>, ApiEnvelope>>( '/platform/v1/last-leg/dispatches', { params: query }, ) return unwrapApiResponse(response) } export async function listDispatchCandidates(query: DispatchCandidateQuery) { const response = await overseasHttp.get, ApiEnvelope>( '/platform/v1/last-leg/dispatches/candidates', { params: query }, ) return unwrapApiResponse(response) } export async function preArrangeDispatch(payload: PreArrangeDispatchPayload) { const response = await overseasHttp.post, ApiEnvelope>( '/platform/v1/last-leg/dispatches/pre-arrange', payload, ) return unwrapApiResponse(response) } export async function lockDispatchDraftPallet(planPalletId: string, draftToken: string) { const response = await overseasHttp.post, ApiEnvelope>( '/platform/v1/last-leg/dispatches/draft-locks/lock', { planPalletId, draftToken }, ) return unwrapApiResponse(response) } export async function unlockDispatchDraftPallet(planPalletId: string, draftToken: string) { const response = await overseasHttp.post, ApiEnvelope>( '/platform/v1/last-leg/dispatches/draft-locks/unlock', { planPalletId, draftToken }, ) return unwrapApiResponse(response) } export async function releaseDispatchDraft(draftToken: string) { const response = await overseasHttp.post, ApiEnvelope>( '/platform/v1/last-leg/dispatches/draft-locks/release', { draftToken }, ) return unwrapApiResponse(response) }