import { requestClient } from '#/api/request';

enum Api {
  base = '/examQuestion/question',
  list = '/examQuestion/question/list',
  randomList = '/examQuestion/question/random-list',
}

export interface Question {
  id: number;
  categoryId: number;
  questionType: string;
  questionContent: string;
  options: string;
  correctAnswer: string;
  answerAnalysis: string;
  analysisReference: string;
  questionStatus: string;
  difficultyLevel: string;
  score: number;
  delFlag: string;
}

/**
 * 获取试题列表
 */
async function questionList(params?: any) {
  return requestClient.get<Question>(Api.list, { params });
}

async function questionDetail(id: number) {
  return requestClient.get<Question>(`${Api.base}/${id}`);
}
// 新增试题分类
function addQuestion(question: Question) {
  return requestClient.post(Api.base, question, {
    successMessageMode: 'message',
  });
}
// 修改试题分类
function updateQuestion(question: Question) {
  return requestClient.put(Api.base, question, {
    successMessageMode: 'message',
  });
}
// 删除试题分类
function deleteQuestion(ids: number[]) {
  return requestClient.delete(`${Api.base}/${ids.join(',')}`, {
    successMessageMode: 'message',
  });
}

function randomQuestionList(params?: any) {
  return requestClient.get<Question>(Api.randomList, { params });
}

export {
  addQuestion,
  deleteQuestion,
  questionDetail,
  questionList,
  randomQuestionList,
  updateQuestion,
};
