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

enum Api {
  base = '/exam/exam',
  list = '/exam/exam/list',
}

export interface Exam {
  id: number;
  categoryId: number;
  categoryName: string;
  examName: string;
  paperId: number;
  examStartTime: string;
  examEndTime: string;
  examDuration: number;
  passScore: number;
  isLimit: number;
  isSubjective: number;
  examStatus: string;
  createTime: string;
  updateTime: string;
  delFlag: string;
}

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

/**
 * 获取试卷详情
 */
async function examDetail(id: number) {
  return requestClient.get<Exam>(`${Api.base}/${id}`);
}

/**
 * 新增试卷
 */
function addExam(params: any) {
  return requestClient.post(Api.base, params, {
    successMessageMode: 'message',
  });
}
/**
 * 修改试卷
 */
function updateExam(params: any) {
  return requestClient.put(Api.base, params, {
    successMessageMode: 'message',
  });
}
// 删除试卷分类
function deleteExam(ids: number[]) {
  return requestClient.delete(`${Api.base}/${ids.join(',')}`, {
    successMessageMode: 'message',
  });
}

// 我的待考试卷列表
async function myPendingExamList(params?: any) {
  return requestClient.get<Exam>(`${Api.base}/my-start-list`, { params });
}

// 我的已考试卷列表
async function myEndExamList(params?: any) {
  return requestClient.get<Exam>(`${Api.base}/my-end-list`, { params });
}

// 考试试卷详情
async function examPaperDetail(id: number) {
  return requestClient.get<Exam>(`${Api.base}/paper/${id}`);
}

// 人工阅卷
async function startExamList(params?: any) {
  return requestClient.get<Exam>(`${Api.base}/start-list`, { params });
}

export {
  addExam,
  deleteExam,
  examDetail,
  examList,
  examPaperDetail,
  myEndExamList,
  myPendingExamList,
  startExamList,
  updateExam,
};
