import axios, { AxiosResponse } from 'axios';
import {
  StudentItem,
  StudentListPageParam,
  StudentListPageRes,
  StudentUpdateParam,
} from './types/student';

// 考生管理
// 获取考生列表 (分页)
export function getStudentList(
  params: StudentListPageParam
): Promise<StudentListPageRes> {
  return axios.post('/api/admin/student/list', {}, { params });
}
// 新增或编辑考生
export function updateStudent(data: StudentUpdateParam): Promise<StudentItem> {
  if (data.id) {
    return axios.post('/api/admin/student/update', data);
  }
  return axios.post('/api/admin/student/add', data);
}

// 删除考生
export function deleteStudent(id: number): Promise<StudentItem> {
  return axios.post('/api/admin/student/delete', {}, { params: { id } });
}

// 重置违纪
export function resetBreach(id: number): Promise<StudentItem> {
  return axios.post('/api/admin/student/updateBreach', {}, { params: { id } });
}

// 导出考生
export function exportStudent(
  params: Record<string, any>
): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/export',
    {},
    {
      responseType: 'blob',
      params,
    }
  );
}

// 下载考生导入模板
export function studentTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/template',
    {},
    {
      responseType: 'blob',
    }
  );
}
// 下载缺考考生导入模板
export function absentStudentTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/absentTemplate',
    {},
    {
      responseType: 'blob',
    }
  );
}
// 下载违纪考生导入模板
export function breachStudentTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/breachTemplate',
    {},
    {
      responseType: 'blob',
    }
  );
}

// 下载整理异常导入模板
export function exceptionStudentTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/exceptionTemplate',
    {},
    {
      responseType: 'blob',
    }
  );
}

// 下载多媒体考生上传模板
export function mediaStudentTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/mediaTemplate',
    {},
    {
      responseType: 'blob',
    }
  );
}
