import type { Freight, PaginatedResponse } from "@edr/types";

import { api } from "../utils/api";

export interface CreateBookingPayload {
  reference: string;
  customerId: string;
  scheduledDate: string;
  totalAmount: number;
  trainId?: string;
}

export const bookingsService = {
  list: async (): Promise<PaginatedResponse<Freight.IBooking>> => {
    const { data } = await api.get("/bookings");
    return data.data;
  },
  get: async (id: string): Promise<Freight.IBooking> => {
    const { data } = await api.get(`/bookings/${id}`);
    return data.data;
  },
  create: async (payload: CreateBookingPayload): Promise<Freight.IBooking> => {
    const { data } = await api.post("/bookings", payload);
    return data.data;
  },
  remove: async (id: string): Promise<void> => {
    await api.delete(`/bookings/${id}`);
  },
};
