import axios from 'axios';
import {
  ExamListPageParam,
  ExamListPageRes,
  ExamItem,
  ExamUpdateParam,
  ExamStatDetailInfo,
} from './types/exam';

// 考试列表
export function getExamList(
  params: ExamListPageParam
): Promise<ExamListPageRes> {
  return axios.post('/api/admin/exam/listt', {}, { params });
}
// 考试详情
export function getExamDetail(examId: number): Promise<ExamItem> {
  return axios.post('/api/admin/exam/find', {}, { examId });
}

// 新增或编辑考试
export function updateExam(data: ExamUpdateParam): Promise<ExamItem> {
  const ndata = { ...data };
  if (ndata.sheetConfig) {
    ndata.sheetConfig = JSON.stringify(ndata.sheetConfig);
  }
  if (ndata.id) {
    return axios.post('/api/admin/exam/update', ndata);
  }
  return axios.post('/api/admin/exam/save', ndata);
}

// 获取考试统计详情信息
export function getExamStatisticInfo(
  examId: number
): Promise<ExamStatDetailInfo> {
  return axios.post('/api/admin/exam/detail', {}, { params: { examId } });
}
