import { api as client } from '../auth/http'; import { URL_CONSTANTS } from '@/constants/URLS'; import { unwrap } from '@/utils/endpoint'; import type { AssignCustomsRiskPayload, CreateDjiboutiIncidentPayload, CreateEmptyContainerReturnPayload, LoadEmptyContainersOnTrainPayload, DjiboutiIncident, EmptyContainerReturn, ImportCustomsFinalization, ImportOperationActionPayload, RecordDeclarationPayload, UpdateEmptyContainerReturnStatusPayload, UploadImportCustomsDocumentPayload, } from '@/types/importOperations'; export const importOperationsService = { listIncidents: async (bookingId?: string): Promise => { const response = await client.get( URL_CONSTANTS.IMPORT_OPERATIONS.DJIBOUTI_INCIDENTS, { params: { bookingId } }, ); return unwrap(response.data); }, createIncident: async ( payload: CreateDjiboutiIncidentPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.DJIBOUTI_INCIDENTS, payload, ); return unwrap(response.data); }, getCustoms: async (bookingId: string): Promise => { const response = await client.get( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS(bookingId), ); return unwrap(response.data); }, uploadCustomsDocument: async ( bookingId: string, payload: UploadImportCustomsDocumentPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_DOCUMENTS(bookingId), payload, ); return unwrap(response.data); }, recordDeclaration: async ( bookingId: string, payload: RecordDeclarationPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_DECLARATION(bookingId), payload, ); return unwrap(response.data); }, notifyDutiesTaxes: async ( bookingId: string, payload: ImportOperationActionPayload = {}, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_NOTIFY_DUTIES_TAXES(bookingId), payload, ); return unwrap(response.data); }, markDutiesTaxesPaid: async ( bookingId: string, payload: ImportOperationActionPayload = {}, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_DUTIES_TAXES_PAID(bookingId), payload, ); return unwrap(response.data); }, assignRisk: async ( bookingId: string, payload: AssignCustomsRiskPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_RISK(bookingId), payload, ); return unwrap(response.data); }, markReleasePermitted: async ( bookingId: string, payload: ImportOperationActionPayload = {}, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.CUSTOMS_RELEASE_PERMITTED(bookingId), payload, ); return unwrap(response.data); }, listEmptyReturns: async (): Promise => { const response = await client.get( URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS, ); return unwrap(response.data); }, createEmptyReturn: async ( payload: CreateEmptyContainerReturnPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS, payload, ); return unwrap(response.data); }, loadEmptyContainersOnTrain: async ( payload: LoadEmptyContainersOnTrainPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURNS_LOAD_ON_TRAIN, payload, ); return unwrap(response.data); }, updateEmptyReturnStatus: async ( id: string, payload: UpdateEmptyContainerReturnStatusPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURN_STATUS(id), payload, ); return unwrap(response.data); }, /** Equipment interchange receipt — the doc handed to the customer at handover. */ downloadEquipmentInterchangeDocument: (id: string) => client.get(URL_CONSTANTS.IMPORT_OPERATIONS.EMPTY_CONTAINER_RETURN_DOCUMENT(id), { responseType: 'blob', }), };