import api from "./api";

export const authService = {
  async login(username, password) {
    const formData = new URLSearchParams();
    formData.append("username", username);
    formData.append("password", password);

    const response = await api.post("/auth/token", formData, {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    });
    return response.data;
  },

  async register(username, password, fullName) {
    const payload = {
      username,
      password,
      full_name: fullName,
    };
    const response = await api.post("/auth/register", payload);
    return response.data;
  },

  async getMe() {
    const response = await api.get("/auth/me");
    return response.data;
  },

  async getApprovals() {
    const response = await api.get("/admin/approvals");
    return response.data;
  },

  async approveUser(username) {
    const response = await api.post(`/admin/approve/${username}`);
    return response.data;
  },

  async denyUser(username) {
    const response = await api.post(`/admin/deny/${username}`);
    return response.data;
  },
};
