import axios, { AxiosResponse } from 'axios';
import type {
  OptionItem,
  TaskListPageParam,
  TaskListPageRes,
  TaskItemDetail,
  TaskRuleUpdateParams,
  TaskTimeUpdateParams,
  TaskNoticeUpdateParams,
  OrderRecordListPageRes,
  OrderRecordListPageParam,
  StudentExportListPageRes,
  OrderRecordPrintTimeItem,
  OrderRecordPrintParam,
  ExportOrderRecordDetailParam,
  AgentQueryParam,
  RoomQueryParam,
  OrderPeriodSetItem,
  TimePeriodItem,
} from './types/order';
import { AbleParams, PageParams } from './types/common';

// 通用查询
// 通用查询-任务查询
export function taskQuery(): Promise<OptionItem[]> {
  return axios.post('/api/admin/apply/task/list', {});
}
// 通用查询-教学点查询
export function teachingQuery(params: {
  flag?: boolean;
}): Promise<OptionItem[]> {
  return axios.post('/api/admin/apply/teaching/list', {}, { params });
}
// 通用查询-考点查询
export function agentQuery(params: AgentQueryParam): Promise<OptionItem[]> {
  return axios.post('/api/admin/apply/agent/list', {}, { params });
}
// 通用查询-考场查询
export function roomQuery(params: RoomQueryParam): Promise<OptionItem[]> {
  return axios.post('/api/admin/room/list', {}, { params });
}
// 通用查询-城市查询
export function cityQuery(): Promise<OptionItem[]> {
  return axios.post('/api/admin/teaching/city/list', {});
}

// 预约任务管理
// 预约任务管理-查询
export function taskListPage(
  params: TaskListPageParam
): Promise<TaskListPageRes> {
  return axios.post('/api/admin/apply/task/page', params);
}
// 预约任务管理-详情
export function taskDetailInfo(id: number): Promise<TaskItemDetail> {
  return axios.post('/api/admin/apply/task/find', {}, { params: { id } });
}
// 预约任务管理-新增编辑规则
export function updateTaskRule(
  datas: TaskRuleUpdateParams
): Promise<{ id: number }> {
  return axios.post('/api/admin/apply/task/rule/save', datas);
}
// 预约任务管理-编辑时段
export function updateTaskTime(
  datas: TaskTimeUpdateParams
): Promise<{ id: number }> {
  return axios.post('/api/admin/apply/task/time/save', datas);
}
// 预约任务管理-编辑说明
export function updateTaskNotice(
  datas: TaskNoticeUpdateParams
): Promise<{ id: number }> {
  return axios.post('/api/admin/apply/task/notice/save', datas);
}
// 预约任务管理-启用禁用
export function ableTask(params: AbleParams): Promise<boolean> {
  return axios.post('/api/admin/apply/task/enable', {}, { params });
}
// 预约任务管理-删除时段
export function deleteTaskTime(timeId: number): Promise<boolean> {
  return axios.post(
    '/api/admin/apply/task/rule/delete',
    {},
    { params: { timeId } }
  );
}

// 考生信息导入
// 考生信息导入分页
export function studentImportListPage(
  params: PageParams
): Promise<StudentExportListPageRes> {
  return axios.post('/api/admin/std/page', params);
}
// 考生信息导入-导入模板下载
export function studentInfoTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.get('/api/admin/std/import/template', {
    responseType: 'blob',
  });
}

// 预约名单
// 预约名单详情分页
export function orderRecordListPage(
  params: OrderRecordListPageParam
): Promise<OrderRecordListPageRes> {
  return axios.post('/api/admin/apply/std/page', params);
}

export function orderRecordListPage2(
  params: OrderRecordListPageParam
): Promise<OrderRecordListPageRes> {
  return axios.post('/api/admin/student/page', params);
}

// 预约名单详情-取消预约
export function orderRecordCancel(id: number): Promise<boolean> {
  return axios.post('/api/admin/apply/std/cancel', {}, { params: { id } });
}
// 删除预约
export function orderRecordDelete(ids: string) {
  return axios.post('/api/admin/student/delete', {}, { params: { ids } });
}
// 预约名单详情-一键自动分配
export function orderRecordAutoAssign(params: {
  taskId: number;
}): Promise<boolean> {
  return axios.post('/api/admin/apply/std/auto/assign', {}, { params });
}
// 预约名单详情-导入模板下载
export function orderRecordTemplate(): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/apply/imp/template',
    {},
    {
      responseType: 'blob',
    }
  );
}

export function orderDetailExport(data: any): Promise<AxiosResponse<Blob>> {
  return axios.post('/api/admin/apply/detail/export', data, {
    responseType: 'blob',
  });
}

// 预约名单详情分页
export function orderRecordPrintTimeListPage(): Promise<
  OrderRecordPrintTimeItem[]
> {
  return axios.post('/api/admin/apply/sign/in/date', {});
}
// 预约名单详情-打印签到表
export function orderRecordPrint(
  params: OrderRecordPrintParam
): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/apply/std/auto/sign/in/print',
    {},
    {
      responseType: 'blob',
      params,
    }
  );
}
// 预约名单详情-导出考场预约情况表
export function exportOrderRecordDetail(
  params: ExportOrderRecordDetailParam
): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/apply/export/teaching/available',
    {},
    {
      responseType: 'blob',
      params,
    }
  );
}

// 时段列表(对应表格第一行)
export function getTimeSliceList(params: {
  taskId: string;
}): Promise<string[]> {
  return axios.post('/api/admin/time/period/exam/site/list', {}, { params });
}
// 时段设置列表
export function getDateAndTimeList(params: any) {
  return axios.post(
    '/api/admin/time/period/exam/site/detail/list',
    {},
    { params }
  );
}

// 预约设置保存
export function saveReservation(data: any, params: any) {
  return axios.post('/api/admin/time/period/exam/site/save', data, { params });
}

// 开启/关闭 自主预约
export function toggleSelfYYStatus(params: any) {
  return axios.post('/api/admin/teaching/selfApplyEnable', {}, { params });
}

// 管理开始关闭自主预约
// 查询状态
export function adminSwitchReservationStatus() {
  return axios.post(
    '/api/admin/time/period/exam/site/switch/find',
    {},
    {
      params: {
        propKey: 'APPLY_SWITCH',
      },
    }
  );
}
// 修改状态
export function adminSwitchReservation(status: boolean) {
  return axios.post(
    '/api/admin/time/period/exam/site/switch/enable',
    {},
    { params: { status } }
  );
}

// 考场排版设置
// 预约时段设置列表
export function getRoomDateAndTimeList(
  examRoomId: number
): Promise<OrderPeriodSetItem[]> {
  return axios.post(
    '/api/admin/time/period/exam/room/detail/list',
    {},
    { params: { examRoomId } }
  );
}
// 预约时段设置保存
export function saveScheduling(data: TimePeriodItem[], examRoomId: number) {
  return axios.post('/api/admin/time/period/exam/room/save', data, {
    params: { examRoomId },
  });
}

export function getUserList(data: any): any {
  return axios.post('/api/admin/user/page', data);
}

export function addUser(data: any): any {
  return axios.post('/api/admin/user/save', data);
}
export function ableUser(params: any): any {
  return axios.post('/api/admin/user/enable', {}, { params });
}
export function resetUserPwd(params: any): any {
  return axios.post('/api/admin/user/reset/password', {}, { params });
}
export function getMyTasks(data: any): any {
  return axios.post('/api/admin/async/task/page', data);
}

export function getTaskTypes(): any {
  return axios.post('/api/admin/async/task/type/list');
}

export function studentExport(params: any): Promise<AxiosResponse<Blob>> {
  return axios.post(
    '/api/admin/student/export',
    {},
    {
      responseType: 'blob',
      params,
    }
  );
}
