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

enum Api {
  base = '/examPaper/paper',
  list = '/examPaper/paper/list',
  question = '/examPaperQuestion/question',
}

export interface Paper {
  id: number;
  categoryId: number;
  paparName: string;
  paperDescription: string;
  totalScore: number;
  paperStatus: string;
  questionCount: number;
  bigQuestionNames: string;
  createTime: string;
  updateTime: string;
  delFlag: string;
}

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

async function correctRates(id: number, params?: any) {
  return requestClient.get(`${Api.question}/correct-rates/${id}`, { params });
}

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

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

export {
  addPaper,
  correctRates,
  deletePaper,
  paperDetail,
  paperList,
  updatePaper,
};
