import { api } from "../auth/http";

type ListResponse<T> = T[] | { data: T[] };

const asList = <T>(payload: ListResponse<T>): T[] =>
  Array.isArray(payload) ? payload : payload.data;

export const cargoTypesService = {
  async getCargoTypes() {
    const response = await api.get<ListResponse<unknown>>('/cargo-types', {
      params: { isActive: true, pageSize: 500 },
    });
    return asList(response.data);
  },
};
