import api from "src/api";

export const getProducts = async (params) => {
  const { data } = await api.get("/product", { params });
  return data.payload;
};

export const getProductsForSelect = async () => {
  const { data } = await api.get("/selects/products");
  return data.payload;
};

export const createProduct = async (payload) => {
  const { data } = await api.post("/product", payload);
  return data.payload;
};

export const updateProduct = async (id, payload) => {
  const { data } = await api.put(`/product/${id}`, payload);
  return data.payload;
};

export const deleteProduct = async (id) => {
  const { data } = await api.delete(`/product/${id}`);
  return data;
};

export const adjustProductStock = async (id, payload) => {
  const { data } = await api.patch(`/product/${id}/stock`, payload);
  return data.payload;
};

export const importProducts = async (file) => {
  const formData = new FormData();
  formData.append("file", file);
  const { data } = await api.post("/product/import", formData, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return data.payload;
};
