import axios from 'axios';
import {
  SubjectTotalScoreStatItem,
  SubjectListPageParam,
  SubjectListPageRes,
  SubjectSettingInfo,
  PaperStructureListPageRes,
  PaperStructureItem,
  PaperStructureUpdateParams,
  SubjectItem,
  OptionalQuestionItem,
  OptionalRuleUpdateParam,
  OptionalRuleItem,
} from './types/subject';

// 科目管理
// 获取科目总分统计列表
export function getSubjectTotalScoreStatList(
  examId: number
): Promise<SubjectTotalScoreStatItem[]> {
  return axios.get(`/api/subject/total-score-stat/${examId}`);
}

// 获取科目列表
export function getSubjectList(
  params: SubjectListPageParam
): Promise<SubjectListPageRes> {
  return axios.post('/api/subject/list', {}, { params });
}
// 获取科目详情
export function getSubjectDetail(subjectId: number): Promise<SubjectItem> {
  return axios.post('/api/subject/list', {}, { params: { subjectId } });
}

// 科目分析计算
export function subjectAnalysis(
  examId: number,
  subjectId?: number
): Promise<boolean> {
  return axios.post('/api/subject/analysis', { params: { examId, subjectId } });
}

// 客观题统分
export function subjectObjectiveMarkScore(examId: number): Promise<boolean> {
  return axios.post(
    '/api/subject/objective-stat',
    {},
    {
      params: { examId },
    }
  );
}

// 获取科目试卷结构列表
export function getPaperStructureList(
  subjectId: number
): Promise<PaperStructureListPageRes> {
  return axios.post(`/api/subject/paper-structure/${subjectId}`);
}

// 获取科目设置信息
export function getSubjectSetting(
  subjectId: number
): Promise<SubjectSettingInfo> {
  return axios.post('/api/subject/setting', {}, { params: { subjectId } });
}
// 保存科目设置信息
export function saveSubjectSetting(
  data: SubjectSettingInfo
): Promise<SubjectSettingInfo> {
  return axios.post('/api/subject/setting', data);
}

// 新增/编辑试卷结构
export function savePaperStructure(
  data: PaperStructureUpdateParams
): Promise<PaperStructureItem> {
  return axios.post('/api/subject/paper-structure', data);
}

// 批量删除试卷结构
export function deletePaperStructures(ids: number[]): Promise<boolean> {
  return axios.post(
    '/api/subject/paper-structure/batch',
    {},
    {
      params: { ids },
    }
  );
}

// 选做题设置
// 获取选做题试题列表
export function getOptionalQuestionList(
  subjectId: number
): Promise<OptionalQuestionItem[]> {
  return axios.post(
    '/api/subject/optional-question/list',
    {},
    {
      params: { subjectId },
    }
  );
}

// 获取选做题规则列表
export function getOptionalQuestionRuleList(
  subjectId: number
): Promise<OptionalRuleItem[]> {
  return axios.post(
    '/api/subject/optional-question/rule/list',
    {},
    {
      params: { subjectId },
    }
  );
}

// 保存选做题设置
export function saveOptionalQuestionRule(
  params: OptionalRuleUpdateParam
): Promise<boolean> {
  return axios.post('/api/subject/optional-question/rule', params);
}

// 删除选做题规则
export function deleteOptionalQuestionRule(id: number): Promise<boolean> {
  return axios.post(
    '/api/subject/optional-question/rule/delete',
    {},
    {
      params: { id },
    }
  );
}
