import api from "src/api";

export const getUnits = async () => {
  const { data } = await api.get("/unit");
  return data.payload;
};

export const getUnit = async (id) => {
  const { data } = await api.get(`/unit/${id}`);
  return data.payload;
};

export const createUnit = async (formData) => {
  const { data } = await api.post("/unit", formData, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  
  return data.payload;
};

export const updateUnit = async (id, formData) => {
  formData.append("_method", "PUT");
  const { data } = await api.post(`/unit/${id}`, formData, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return data.payload;
};

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

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