import api from "src/api";

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

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

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

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

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

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

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

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

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

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

export const deleteStudentContract = async (id) => {
  await api.delete(`/franchisee/contracts/${id}`);
};
