import api from "src/api";

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

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

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

export const updateStudent = async (payload, id) => {
  if (payload instanceof FormData) {
    payload.append('_method', 'PUT');
    const { data } = await api.post(`/student/${id}`, payload);
    return data.payload;
  }
  const { data } = await api.put(`/student/${id}`, payload);
  return data.payload;
};

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