import api from "src/api";

export const getStudents = async (params = {}) => {
  const { data } = await api.get("/franchisee/students", { params });
  return data.payload;
};

export const getStudentsForSelect = async () => {
  const { data } = await api.get("/selects/franchisee/students");
  return data.payload;
};

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

export const createStudent = async (student) => {
  const { data } = await api.post("/franchisee/students", student);
  return data.payload;
};

export const createStudentRegistrationDraft = async (student) => {
  const { data } = await api.post(
    "/franchisee/students/registration-drafts",
    student,
  );

  return data.payload;
};

export const updateStudent = async (payload, id) => {
  if (payload instanceof FormData) {
    payload.append('_method', 'PUT');

    const { data } = await api.post(`/franchisee/students/${id}`, payload);

    return data.payload;
  }

  const { data } = await api.put(`/franchisee/students/${id}`, payload);

  return data.payload;
};

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