import { api } from '../auth/http'; import { URL_CONSTANTS } from '@/constants/URLS'; export const FIRST_MILE_STATUSES = [ 'PAYMENT_PENDING', 'READY_TO_TRANSIT', 'IN_TRANSIT', 'RECEIVED_TO_PORT', ] as const; export type FirstMileApiStatus = (typeof FIRST_MILE_STATUSES)[number]; export interface FirstMileBooking { id: string; reference: string; firstMilePickupAddress?: string | null; cargoFreeText?: string | null; cargoTotalWeightVgm: number; totalAmount: number; scheduledDate?: string | null; company?: { id: string; name?: string; phone?: string | null; contactPersonName?: string | null; contactPersonPhone?: string | null } | null; serviceType?: { id: string; label?: string } | null; originYard?: { id: string; label?: string } | null; destinationYard?: { id: string; label?: string } | null; cargoType?: { id: string; label?: string } | null; } export interface FirstMileVehicle { id: string; plateNumber: string; manufacturer: string; model: string; code?: string | null; powerPlateNo?: string | null; trailerPlateNo?: string | null; } export interface FirstMileRecord { id: string; bookingId: string; status: FirstMileApiStatus; advancedPayment: number; remainingPayment: number; estimatedKm?: number | null; exactKm?: number | null; vehicleId?: string | null; booking?: FirstMileBooking | null; vehicle?: FirstMileVehicle | null; createdAt: string; updatedAt: string; } export interface FirstMileListResponse { data: FirstMileRecord[]; meta: { total: number; page: number; pageSize: number; totalPages: number }; } const FM = URL_CONSTANTS.FIRST_MILE; export const firstMileService = { list: (pageSize = 1000) => api.get(`${FM.BASE}?pageSize=${pageSize}`), getById: (id: string) => api.get(FM.BY_ID(id)), update: (id: string, data: { status?: FirstMileApiStatus; vehicleId?: string | null }) => api.patch(FM.BY_ID(id), data), accept: (bookingReference: string) => api.post(FM.ACCEPT(bookingReference)), };