import axios from "axios";

export const deleteUser = async (userId) => {
  try {
    const response = await axios.delete(`/user/${userId}`);
    return response.data;
  } catch (err) {
    console.error(err);
    return null;
  }
};

export const createUser = async (username, password, confirmation) => {
  try {
    const response = await axios.post("/user", {
      username,
      password,
      confirmation,
    });
    return response.data;
  } catch (err) {
    console.error(err);
    return null;
  }
};

export const updateUser = async (settings) => {
  try {
    console.log("try");
    const formData = new FormData();
    formData.append("_id", settings._id);
    formData.append("username", settings.username);
    formData.append("password", settings.password);
    formData.append("confirmation", settings.confirmation);
    formData.append("old_password", settings.old_password);

    const response = await axios.put(`/user/${settings._id}`, formData);
    return response.data;
  } catch (err) {
    console.error(err);
    return null;
  }
};
