import api from "src/api";

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

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

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

export const updateUser = async (user, id) => {
  const { data } = await api.put(`/user/${id}`, 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-types");
  return data.payload;
};

export const sendCode = async (email, phone) => {
  const data = await api.post("/client-send-code", { email, phone });
  return data;
}

export const validateCode = async (email, phone, code, isLogin) => {
  const data = await api.post("/validate-code-client", { email, phone, code, isLogin });
  return data;
}

export const createUserAndClient = async (data) => {
  const response = await api.post("/register-client", data);
  return response;
}

export const updateMe = async (data) => {
  const { data: res } = await api.put('/me', data);
  return res.payload;
};
