import api from "src/api";

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

export const getStudentContracts = async (studentId) => {
  const { data } = await api.get("/student-contract", { params: { student_id: studentId } });
  return data.payload;
};

export const getAllContracts = async () => {
  const { data } = await api.get("/student-contract");
  return data.payload;
};

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

export const updateStudentContract = async (id, payload) => {
  const { data } = await api.put(`/student-contract/${id}`, payload);
  return data.payload;
};

export const attachContractFile = async (id, formData) => {
  const { data } = await api.post(`/student-contract/${id}/file`, formData, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return data.payload;
};

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

export const freezeContract = async (id, months) => {
  const { data } = await api.post(`/student-contract/${id}/freeze`, { months });
  return data.payload;
};

export const cancelContract = async (id) => {
  const { data } = await api.post(`/student-contract/${id}/cancel`);
  return data.payload;
};

export const reactivateContract = async (id) => {
  const { data } = await api.post(`/student-contract/${id}/reactivate`);
  return data.payload;
};

export const deleteStudentContract = async (id) => {
  await api.delete(`/student-contract/${id}`);
};
