import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' export const deliveryDocumentCategories = [ { category: 'LOADING_PHOTO', label: '装车照片' }, { category: 'BOL', label: 'BOL文件(含签名)' }, { category: 'RECEIPT', label: '签收文件(POD签收/快递签收)' }, ] as const export type DeliveryDocumentCategory = typeof deliveryDocumentCategories[number]['category'] export interface DeliveryDocumentFile { fileId: string; fileName: string; contentType: string | null; sizeBytes: number; uploadedAt: string } export interface DeliveryDocumentCategorySummary { category: DeliveryDocumentCategory; status: 'UPLOADED' | 'MISSING'; fileCount: number } export interface DeliveryDocumentSummary { uploadedCategoryCount: number; totalCategoryCount: number; categories: DeliveryDocumentCategorySummary[] } export interface DeliveryDocuments extends DeliveryDocumentSummary { deliveryNo: string; customerId: string; version: number; bolNo: string | null categories: Array allowedActions: string[]; replayed: boolean } export interface SaveDeliveryDocuments { expectedVersion: number; idempotencyKey: string; bolNo: string | null; documents: Array<{ category: DeliveryDocumentCategory; fileIds: string[] }> } const path = (deliveryNo: string) => `/platform/v1/last-leg/delivery-orders/${encodeURIComponent(deliveryNo)}/documents` export async function getDeliveryDocuments(deliveryNo: string, customerId: string) { return unwrapApiResponse(await http.get, ApiEnvelope>(path(deliveryNo), { params: { customerId } })) } export async function saveDeliveryDocuments(deliveryNo: string, customerId: string, body: SaveDeliveryDocuments) { return unwrapApiResponse(await http.put, ApiEnvelope>(path(deliveryNo), body, { params: { customerId } })) } export async function uploadDeliveryDocument(deliveryNo: string, customerId: string, category: DeliveryDocumentCategory, file: File) { const body = new FormData() body.append('file', file) return unwrapApiResponse(await http.post, ApiEnvelope>(`${path(deliveryNo)}/${category}/files`, body, { params: { customerId } })) } export async function downloadDeliveryDocument(deliveryNo: string, customerId: string, category: DeliveryDocumentCategory, fileId: string) { return http.get(`${path(deliveryNo)}/${category}/files/${encodeURIComponent(fileId)}/download`, { params: { customerId }, responseType: 'blob' }) }