import axios, { AxiosResponse } from 'axios';
import {
  RejectListPageParams,
  RejectListFilter,
  RejectListPageRes,
  RejectStatisticsListParams,
  RejectStatisticsFilter,
  RejectStatisticsListRes,
  RejectTypeItem,
  RejectTypeUpdateParam,
} from './types/reject';

// 获取打回列表
export function getRejectList(
  params: RejectListPageParams
): Promise<RejectListPageRes> {
  return axios.post('/api/admin/exam/reject/list/history', params);
}
// 获取打回记录列表
export function getRejectRecordList(
  params: RejectListPageParams
): Promise<RejectListPageRes> {
  return axios.post('/api/admin/exam/reject/list/history', params);
}

// 导出打回记录列表
export function exportRejectRecord(
  params: RejectListFilter
): Promise<AxiosResponse<Blob>> {
  return axios.post('/api/admin/exam/reject/list/history/export', params, {
    responseType: 'blob',
  });
}

// 获取打回统计列表
export function getRejectStatisticsList(
  params: RejectStatisticsListParams
): Promise<RejectStatisticsListRes> {
  const url = params.showGroupNumber
    ? '/api/admin/exam/reject/list/group'
    : '/api/admin/exam/reject/list/subject';
  return axios.post(url, params);
}

// 打回统计列表导出
export function exportRejectStat(
  params: RejectStatisticsFilter
): Promise<AxiosResponse<Blob>> {
  const url = params.showGroupNumber
    ? '/api/admin/exam/reject/list/group/export'
    : '/api/admin/exam/reject/list/subject/export';
  return axios.post(url, params, { responseType: 'blob' });
}

// 打回类型 ------------->
// 查询打回类型
export function getRejectTypeList(examId: number): Promise<RejectTypeItem[]> {
  return axios.post('/api/admin/exam/reject/type/list', { examId });
}
// 新增/修改打回类型
export function updateRejectType(params: RejectTypeUpdateParam): Promise<any> {
  if (params.id) {
    return axios.post('/api/admin/exam/reject/type/update', params);
  }
  return axios.post('/api/admin/exam/reject/type/save', params);
}
// 删除打回类型
export function deleteRejectType(id: number): Promise<any> {
  return axios.post('/api/admin/exam/reject/type/delete', { id });
}
