import { api as client } from '../auth/http'; import { unwrap } from '@/utils/endpoint'; import { URL_CONSTANTS } from '@/constants/URLS'; import type { CreateTrainSchedulePayload, EligibleContainerBookingsResponse, LocomotiveRecord, TrainScheduleDetail, TrainScheduleFilters, TrainScheduleListItem, TrainSchedulePreviewPayload, TrainSchedulePreviewResponse, YardOption, } from '@/types/trainScheduling'; interface BookingReferenceDataResponse { yard?: YardOption[]; } export const trainSchedulingService = { getEligibleBookings: async ( filters?: TrainScheduleFilters, ): Promise => { const response = await client.get( URL_CONSTANTS.TRAIN_SCHEDULING.ELIGIBLE_BOOKINGS, { params: filters }, ); return unwrap(response.data); }, preview: async ( payload: TrainSchedulePreviewPayload, ): Promise => { const response = await client.post( URL_CONSTANTS.TRAIN_SCHEDULING.PREVIEW, payload, ); return unwrap(response.data); }, createSchedule: async ( payload: CreateTrainSchedulePayload, ): Promise => { const response = await client.post( URL_CONSTANTS.TRAIN_SCHEDULING.SCHEDULES, payload, ); return unwrap(response.data); }, listSchedules: async (): Promise => { const response = await client.get( URL_CONSTANTS.TRAIN_SCHEDULING.SCHEDULES, ); return unwrap(response.data); }, getScheduleById: async (id: string): Promise => { const response = await client.get( URL_CONSTANTS.TRAIN_SCHEDULING.SCHEDULE_BY_ID(id), ); return unwrap(response.data); }, cancelSchedule: async (id: string): Promise => { const response = await client.post( URL_CONSTANTS.TRAIN_SCHEDULING.CANCEL_SCHEDULE(id), {}, ); return unwrap(response.data); }, getAvailableLocomotives: async (): Promise => { const response = await client.get(URL_CONSTANTS.LOCOMOTIVES.BASE, { params: { status: 'AVAILABLE' }, }); return unwrap(response.data); }, getStations: async (): Promise => { const response = await client.get( URL_CONSTANTS.BOOKINGS.REFERENCE_DATA, ); const data = unwrap(response.data); return data.yard ?? []; }, };