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

export const containerService = {
  async getContainers() {
    const response = await api.get('/containers');
    return response.data;
  },
  async getContainersByWagon(wagonId: string) {
    const response = await api.get('/containers', { params: { wagonId } });
    return response.data;
  },
  async createContainer(data: any) {
    const response = await api.post('/containers', data);
    return response.data;
  },
  async updateContainer(id: string, data: any) {
    const response = await api.patch(`/containers/${id}`, data);
    return response.data;
  },
  async deleteContainer(id: string) {
    await api.delete(`/containers/${id}`);
  },
  async assignToWagon(containerId: string, wagonId: string, position?: number) {
    const response = await api.post(`/containers/${containerId}/assign-wagon`, { wagonId, position });
    return response.data;
  },
  async unassignFromWagon(containerId: string) {
    const response = await api.post(`/containers/${containerId}/unassign-wagon`);
    return response.data;
  },
};