const prefix = "/eval";

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

function getTeacherEvalExams({pageSize, pageNum, state}){
  return axios.get(`${prefix}/exam/teacher`, {
    // pageSize、pageNum非必需，state必需，"0 所有， 1 未开始，2 进行中，3 已结束"
    params:{pageSize, pageNum, state}});
}

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

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

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

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

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

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

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

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

function getSamplePaper() {
  return axios.get(`${prefix}/exam/sample`);
}

function getQuestionInfo(id) {
  return axios.get(`${prefix}/questions/${id}`);
}

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

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

function setExamPaperFromSample(examId, sampleExamPaperId){
  return axios.post(`${prefix}/exam/question/sample/${examId}/?sampleExamPaperId=${sampleExamPaperId}`);
}

function getExamSubmitRecordsByUserId(examId) {
  return axios.get(`${prefix}/exam/record/all?examId=${examId}`);
}

function getQuestionList(page,stem,tags,knowledgeName) {
  let params = "";
  if (stem) {
    params += `stem=${stem}&`;
  }
  if (tags) {
    params += `tags=${tags}&`;
  }
  if (knowledgeName) {
    params += `knowledgeName=${knowledgeName}&`;
  }

  return axios.get(`${prefix}/exam/question?${params}pageSize=${page.pageSize}&pageNum=${page.pageNum}`);
}

function setExamPaperQuestions(examId,questions){
  return axios.put(`${prefix}/exam/${examId}/setQuestions`,{questionScoreMap: questions});
}

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

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

function getAllReportByExamId(examId){
  return axios.get(`${prefix}/exam/report/all?examId=${examId}`);
}

function joinPublicExam(examId){
  return axios.put(`${prefix}/exam/invite/withoutCode?examId=${examId}`);
}

function joinExamByInviteCode(inviteCode,examId){
  return axios.put(`${prefix}/exam/invite/withCode?inviteCode=${inviteCode}&examId=${examId}`);
}

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

const evalAPIs = {
  getTeacherEvalExams,
  getTeacherEvalExamsGroupByCourse,
  getStudentEvalExams,
  getStudentEvalExamsGroupByCourse,
  getRecommendEvalExams,
  getRecommendEvalExamsGroupByCourse,
  getTeacherEvalExamsByCourseId,
  getStudentEvalExamsByCourseId,
  createEvalExam,
  getExamQuestions,
  getExamCodeQuestions,
  getSamplePaper,
  getQuestionInfo,
  setExamPaperFromSample,
  getExamSubmitRecordsByUserId,
  getQuestionList,
  setExamPaperQuestions,
  getExamById,
  getExamJoinedUsers,
  getAllReportByExamId,
  joinPublicExam,
  joinExamByInviteCode,
  getExamListByCurrentStudent
};

export default evalAPIs;