import axios, { AxiosResponse } from 'axios';
import {
  SchoolListPageParam,
  SchoolListPageRes,
  SchoolUpdateParam,
  SchoolUpdateAdminParam,
  SchoolStatusInfo,
  AuthInfo,
  AuthUpdateParams,
} from './types/admin';
import { CommonActionRes } from './types/common';

// 学校管理
// 学校管理列表
export function schoolListPage(
  params: SchoolListPageParam
): Promise<SchoolListPageRes> {
  return axios.post('/api/admin/sys/school/list', params);
}
// 学校信息编辑
export function updateSchool(
  datas: SchoolUpdateParam
): Promise<{ id: number }> {
  return axios.post('/api/admin/sys/school/save', datas);
}
// 学校管理员信息编辑
export function updateSchoolAdmin(
  datas: SchoolUpdateAdminParam
): Promise<{ id: number }> {
  return axios.post('/api/admin/sys/school/admin/save', datas);
}
// 获取学校管理员信息
export function getSchoolAdminInfo(
  schoolId: number
): Promise<SchoolUpdateAdminParam> {
  return axios.post(
    '/api/admin/sys/school/admin/info',
    {},
    { params: { schoolId } }
  );
}

// 机构同步
export function syncSchool(): Promise<CommonActionRes> {
  return axios.post('/api/admin/sys/school/sync', {});
}

// 获取学校状态信息
export function getSchoolStatusInfo(): Promise<SchoolStatusInfo> {
  return axios.post('/api/admin/sys/school/status', {});
}

// 导出拆分科目模板
export function splitCourseTemplate(): Promise<AxiosResponse<blob>> {
  return axios.post(
    '/api/admin/school/exportSplitCourseTemplate',
    {},
    { responseType: 'blob' }
  );
}

// 授权管理
// 授权管理信息
export function getAuthInfo(): Promise<AuthInfo> {
  return axios.post('/api/admin/auth/info');
}
// 授权管理信息编辑
export function updateAuthInfo(
  datas: AuthUpdateParams
): Promise<{ id: number }> {
  return axios.post('/api/admin/auth/save', datas);
}

// 导出硬件信息
export function exportHardwareInfo(): Promise<AxiosResponse<blob>> {
  return axios.post('/api/admin/auth/export', {}, { responseType: 'blob' });
}
