import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' export interface ArrivalCalendarEntry { containerBookingId: string cabinetNo: string containerNo?: string | null vesselName?: string | null voyageNo?: string | null destinationPortName?: string | null destinationWarehouseCode?: string | null arrivalAt: string arrivalType: 'ACTUAL' | 'ESTIMATED' } export interface PickupCalendarEntry { containerBookingId: string cabinetNo: string containerNo: string | null destinationPortName: string | null destinationWarehouseCode: string | null fleetSupplierName: string | null pickupAppointmentAt: string | null actualPickupAt: string | null } export interface PickupCalendar { records: PickupCalendarEntry[] truncated: boolean unclassifiedCount: number scopeBasis: 'US_DESTINATION_WAREHOUSE' timeBasis: 'SOURCE_LOCAL_UNSPECIFIED' } export async function listPickupCalendar(query: { from: string; to: string }, signal?: AbortSignal) { return unwrapApiResponse(await http.get, ApiEnvelope>( '/platform/v1/terminal-drayages/calendar', { params: query, signal }, )) } export async function listArrivalCalendar(query: { from: string; to: string }, signal?: AbortSignal) { const response = await http.get, ApiEnvelope>( '/platform/v1/port-schedules/arrival-calendar', { params: query, signal }, ) return unwrapApiResponse(response) } export async function deleteAppointment(appointmentNo: string, version: number, cancelReason: string) { const response = await http.delete, ApiEnvelope>( `/platform/v1/last-leg/inbound-plans/fba-appointments/${encodeURIComponent(appointmentNo)}`, { data: { version, cancelReason } }, ) return unwrapApiResponse(response) } export interface AppointmentCancellation { appointmentNo: string; version: number; cancelReason: string | null; cancelledAt: string snapshot: { fbaWarehouseCode: string; appointmentStatus: string; appointmentRemark: string | null; plannedDate: string | null; plannedAt: string | null; plannedEndAt: string | null; confirmationNo: string | null; appointmentAt: string | null; appointmentEndAt: string | null; timezone: string | null; selectedCount: number } } export async function listAppointmentCancellations(appointmentNo: string, page: number, size: number) { const result = unwrapApiResponse(await http.get, ApiEnvelope<{records: AppointmentCancellation[]; total: number}>>( `/platform/v1/last-leg/inbound-plans/fba-appointments/${encodeURIComponent(appointmentNo)}/cancellations`, {params: {page, size}}, )) return {...result, total: Number(result.total)} } export type AppointmentCancellationSummary = Omit & {fbaWarehouseCode: string; selectedCount: number} export async function listAppointmentCancellationRecords(page: number, size: number) { const result = unwrapApiResponse(await http.get, ApiEnvelope<{records: AppointmentCancellationSummary[]; total: number}>>( '/platform/v1/last-leg/inbound-plans/fba-appointments/cancellations', {params: {page, size}}, )) return {...result, total: Number(result.total)} }