import { overseasDownload, overseasRequest, overseasUpload } from '@/api/overseas.js' import { normalizeReceivingCandidate, normalizeReceivingSession } from '@/api/receiving-adapter.js' const RECEIVING_BASE = '/pda/v1/last-leg/receiving-containers' const current = (suffix = '') => `${RECEIVING_BASE}/current${suffix}` export const listReceivingCandidates = async () => (await overseasRequest('GET', `${RECEIVING_BASE}/candidates`)).map(normalizeReceivingCandidate) export const getCurrentWarehouseProfile = () => overseasRequest('GET', `${RECEIVING_BASE}/warehouse-profile`) export const getReceivingContainer = async (containerNo) => normalizeReceivingSession(await overseasRequest('GET', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}`)) export const prepareReceivingContainer = async (containerNo, request) => normalizeReceivingSession(await overseasRequest('POST', `${RECEIVING_BASE}/${encodeURIComponent(containerNo)}/prepare`, request)) export const uploadCurrentUnloadPhoto = (filePath) => overseasUpload(current('/unload-photos/files'), filePath) export const downloadCurrentUnloadPhoto = (downloadPath) => overseasDownload(downloadPath) export const signCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/sign'), request)) export const getCurrentReceiving = async () => normalizeReceivingSession(await overseasRequest('GET', current())) export const resolveCurrentCarton = (cartonMark) => overseasRequest('POST', current('/cartons/resolve'), { cartonMark }) export const resolveCurrentPallet = (palletCode, inboundCode) => overseasRequest('POST', current('/pallets/resolve'), { palletCode, inboundCode }) export const receiveCurrentBulk = (request) => overseasRequest('POST', current('/receipts/bulk'), request) export const receiveCurrentCarton = (request) => overseasRequest('POST', current('/receipts/carton'), request) export const completeCurrentReceiving = async (request) => normalizeReceivingSession(await overseasRequest('POST', current('/complete'), request))