import axios, { AxiosResponse } from 'axios';
import {
  IssuePaperListPageRes,
  IssuePaperListFilter,
  IssuePaperListPageParam,
  IssuePaperTypeItem,
  IssuePaperTypeUpdateParam,
} from './types/issue-paper';

// 获取问题卷列表
export function getIssuePaperList(
  params: IssuePaperListPageParam
): Promise<IssuePaperListPageRes> {
  return axios.post('/api/admin/exam/problem/history/query', {}, { params });
}

// 重置问题卷
export function resetIssuePaper(libraryIds: number[]): Promise<any> {
  return axios.post('/api/admin/exam/problem/history/restBatch', {
    libraryIds,
  });
}

// 导出问题卷
export function exportIssuePaper(
  params: IssuePaperListFilter
): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/exam/problem/history/export',
    {},
    { params, responseType: 'blob' }
  );
}

// 问题卷类型 ------------->
// 查询问题卷类型
export function getIssuePaperTypeList(
  examId: number
): Promise<IssuePaperTypeItem[]> {
  return axios.post(
    '/api/admin/exam/problem/type/list',
    {},
    { params: { examId } }
  );
}

// 新增/修改问题卷类型
export function updateIssuePaperType(
  params: IssuePaperTypeUpdateParam
): Promise<any> {
  if (params.id) {
    return axios.post('/api/admin/exam/problem/type/update', params);
  }
  return axios.post('/api/admin/exam/problem/type/save', params);
}
// 删除问题卷类型
export function deleteIssuePaperType(id: number): Promise<any> {
  return axios.post(
    '/api/admin/exam/problem/type/delete',
    {},
    { params: { id } }
  );
}
