import axios from "../../../config/axios";
import type {
  ShipmentResponse,
  CreateShipper,
  Shipper,
  ShipmentByIdResponse,
} from "../types/Types";

export const getShipment = async (
  page: number = 1
): Promise<ShipmentResponse> => {
  const { data } = await axios.get<ShipmentResponse>(`/shipment?page=${page}`);
  return data;
};

export const createShipment = async (data: CreateShipper): Promise<Shipper> => {
  const response = await axios.post<Shipper>("/admin/shipment", data);
  return response.data;
};

export const deleteShipment = async (id: string): Promise<void> => {
  const { data } = await axios.delete(`/admin/shipment/${id}`);
  return data;
};

export const getShipmentById = async (id: string): Promise<Shipper> => {
  const { data } = await axios.get<ShipmentByIdResponse>(
    `/admin/shipment/${id}`
  );
  return data.results.shipper;
};

export const updateShipment = async (
  id: string,
  params: CreateShipper
): Promise<Shipper> => {
  const { data } = await axios.patch<Shipper>(`/admin/shipment/${id}`, params);
  return data;
};
