import api from "src/api";

export const getUser = async () => {
  const { data } = await api.get("/user/current/auth");
  return data.payload;
};

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

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

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

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

export const updateUser = async (user, id) => {
  if (user instanceof FormData) {
    user.append("_method", "PUT");
    const { data } = await api.post(`/user/${id}`, user);
    return data.payload;
  }
  const { data } = await api.put(`/user/${id}`, user);
  return data.payload;
};

export const updateUserMe = async (user) => {
  const { data } = await api.put("/user/me", user);
  return data.payload;
};

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

export const userTypes = async () => {
  const { data } = await api.get("/user/all/types");
  return data.payload;
};
