import ApiService from "@/services/ApiService";

const baseUrl = "inventory/products";

export const getAll = async (params = {}) => {
  const response = await ApiService.get(`${baseUrl}`, { params });
  return response.data;
};

export const getById = async (id) => {
  const response = await ApiService.get(`${baseUrl}/${id}`);
  return response.data;
};

export const create = async (payload) => {
  const response = await ApiService.post(`${baseUrl}`, payload);
  return response.data;
};

export const update = async (id, payload) => {
  const response = await ApiService.put(`${baseUrl}/${id}`, payload);
  return response.data;
};

export const remove = async (id) => {
  const response = await ApiService.delete(`${baseUrl}/${id}`);
  return response.data;
};

export const disable = async (id) => {
  const response = await ApiService.patch(`${baseUrl}/${id}/disable`);
  return response.data;
};

export const activate = async (id) => {
  const response = await ApiService.patch(`${baseUrl}/${id}/activate`);
  return response.data;
};

export const getMovements = async (productId, params = {}) => {
  const response = await ApiService.get(`${baseUrl}/${productId}/movements`, { params });
  return response.data;
};

export const createMovement = async (productId, payload) => {
  const response = await ApiService.post(`${baseUrl}/${productId}/movements`, payload);
  return response.data;
};

/** CSV: cabecera sku,quantity (delta de ajuste firmado). Inventario almacén, no POS. */
export const bulkAdjustCsv = async (file) => {
  const formData = new FormData();
  formData.append("file", file);
  const response = await ApiService.post(`${baseUrl}/bulk-adjust-csv`, formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return response.data;
};
