const prefix = "/coder";

import {axios} from "@/requests/axios.config";

function getStudentCoderExams({page, limit}) {
  return axios.get(`${prefix}/exam/student`, {
    // page和limit非必需
    params: {page, limit,}
  });
}

function getStudentCoderExamsGroupByCourse(){
  return axios.get(`${prefix}/exam/student/groupByCourse`);
}

function getTeacherCoderExams({page, limit}) {
  return axios.get(`${prefix}/exam/teacher`, {
    // page和limit非必需
    params: {page, limit,}
  });
}

function getRecommendCoderExams() {
  return axios.get(`${prefix}/exam/recommend`);
}

function getRecommendCoderExamsGroupByCourse(){
  return axios.get(`${prefix}/exam/recommend/groupByCourse`);
}

function getTeacherCoderExamsByCourseId(courseId) {
  return axios.get(`${prefix}/exam/teacher/course`, {params: {courseId,}});
}

function getStudentCoderExamsByCourseId(courseId) {
  return axios.get(`${prefix}/exam/student/course`, {params: {courseId,}});
}

function getTeacherCoderExamsGroupByCourse(){
  return axios.get(`${prefix}/exam/teacher/groupByCourse`);
}

function retrievePageProblem(page, limit, typeStr, name){
  return axios.get(`${prefix}/problem`, {
    params: {
      page,
      limit,
      typeStr,
      name
    }
  });
}

function createCoderExam(data){
  return axios.post(`${prefix}/exam/create`, data);
}

function deleteCoderExam(examId) {
  return axios.delete(`${prefix}/exam/${examId}/delete`);
}

function updateCoderExam(examId, data) {
  return axios.put(`${prefix}/exam/${examId}/update`, data);
}

function getCoderExamByExamId(examId) {
  return axios.get(`${prefix}/exam/${examId}`);
}

function getCoderProblemById(problemId) {
  return axios.get(`${prefix}/problem/${problemId}`);
}

function createCoderProblem(data) {
  return axios.post(`${prefix}/problem`, data);
}

function deleteCoderProblem(problemId) {
  return axios.delete(`${prefix}/problem/${problemId}`);
}

function updateCoderProblem(problemId, data) {
  return axios.put(`${prefix}/problem/${problemId}`, data);
}

function getProblemFile(problemId, filename) {
  return axios.get(`${prefix}/problem/${problemId}/file`, {
    params: {
      "name": encodeURIComponent(filename)
    }
  });
}

function getCoderResultByExamId(examId) {
  return axios.get(`${prefix}/exam/${examId}/result`);
}

function getResultByResultId(resultId) {
  return axios.get(`${prefix}/result/${resultId}`);
}

function getCommitByCommitId(commitId) {
  return axios.get(`${prefix}/commit/${commitId}`);
}

function getRecordByRecordId(recordId) {
  return axios.get(`${prefix}/record/${recordId}`);
}

function getExamIsShownForStu(examId) {
  return axios.get(`${prefix}/exam/${examId}/console`);
}

function changeExamIsShownForStu(examId, status) {
  return axios.post(`${prefix}/exam/${examId}/console?showConsole=${status}`);
}

const coderAPIs = {
  getStudentCoderExams,
  getStudentCoderExamsGroupByCourse,
  getTeacherCoderExams,
  getTeacherCoderExamsGroupByCourse,
  getRecommendCoderExams,
  getRecommendCoderExamsGroupByCourse,
  getTeacherCoderExamsByCourseId,
  getStudentCoderExamsByCourseId,
  retrievePageProblem,

  createCoderExam,
  deleteCoderExam,
  updateCoderExam,
  getCoderExamByExamId,

  getCoderProblemById,
  createCoderProblem,
  deleteCoderProblem,
  updateCoderProblem,
  getProblemFile,

  getCoderResultByExamId,
  getResultByResultId,
  getCommitByCommitId,
  getRecordByRecordId,
  getExamIsShownForStu,
  changeExamIsShownForStu
};

export default coderAPIs;
