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 wagonTypesService = {
  async getWagonTypes() {
    const response = await api.get<ListResponse<unknown>>('/wagon-types');
    return asList(response.data);
  },
};
