import api from "src/api";

export const checkFirstAccess = async (registration) => {
  const { data } = await api.post(
    "/first-access/check",
    { registration },
    { skipSuccessNotify: true },
  );
  return { ...data.payload, message: data.message };
};

export const registerFirstAccess = async (payload) => {
  const formData = new FormData();
  Object.entries(payload).forEach(([key, value]) => {
    if (value !== null && value !== undefined) {
      formData.append(key, value);
    }
  });

  const { data } = await api.post("/first-access/register", formData, {
    headers: { "Content-Type": "multipart/form-data" },
    skipSuccessNotify: true,
  });
  return { ...data.payload, message: data.message };
};

export const getPublicPositions = async () => {
  const { data } = await api.get("/public/positions");
  return data.payload;
};

export const getPublicSectors = async () => {
  const { data } = await api.get("/public/sectors");
  return data.payload;
};
