import { requestClient } from '#/api/request';

export namespace SchoolApi {
  /** 学校列表查询参数 */
  export interface ListParams {
    page?: number;
    limit?: number;
    name?: string;
  }

  /** 学校信息 */
  export interface SchoolInfo {
    id?: number;
    name?: string;
    address?: string;
    description?: string;
    contact?: string;
    phone?: string;
    create_time?: string;
    update_time?: string;
    [key: string]: any;
  }

  /** 学校详情参数 */
  export interface DetailParams {
    id: number;
  }

  /** 保存学校参数 */
  export interface SaveParams extends SchoolInfo {
    id?: number;
  }

  /** 删除学校参数 */
  export interface DeleteParams {
    id: number;
  }

  /** 获取分校账号列表参数 */
  export interface AccountListParams {
    school_id: number;
  }

  /** 分校账号信息 */
  export interface AccountInfo {
    id?: number;
    school_id?: number;
    username?: string;
    password?: string;
    status?: number;
    create_time?: string;
    update_time?: string;
    [key: string]: any;
  }

  /** 保存分校账号参数 */
  export interface SaveAccountParams extends AccountInfo {
    id?: number;
  }

  /** 删除分校账号参数 */
  export interface DeleteAccountParams {
    id: number;
  }
}

/**
 * 获取学校列表（仅超级管理员）
 * GET /api/admin/school/list
 */
export async function getSchoolListApi(params?: SchoolApi.ListParams) {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/school/list', {
    params,
    responseReturn: 'body',
  });
}

/**
 * 获取学校详情（仅超级管理员）
 * GET /api/admin/school/detail
 */
export async function getSchoolDetailApi(params: SchoolApi.DetailParams) {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/school/detail', {
    params,
    responseReturn: 'body',
  });
}

/**
 * 保存学校（新增/编辑）（仅超级管理员）
 * POST /api/admin/school/save
 */
export async function saveSchoolApi(data: SchoolApi.SaveParams) {
  return requestClient.post<SchoolApi.SchoolInfo>('/api/admin/school/save', data);
}

/**
 * 删除学校（仅超级管理员）
 * POST /api/admin/school/delete
 */
export async function deleteSchoolApi(data: SchoolApi.DeleteParams) {
  return requestClient.post('/api/admin/school/delete', data);
}

/**
 * 获取分校账号列表（仅超级管理员）
 * GET /api/admin/school/accountList
 */
export async function getSchoolAccountListApi(params: SchoolApi.AccountListParams) {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/school/accountList', {
    params,
    responseReturn: 'body',
  });
}

/**
 * 保存分校账号（仅超级管理员）
 * POST /api/admin/school/saveAccount
 */
export async function saveSchoolAccountApi(data: SchoolApi.SaveAccountParams) {
  return requestClient.post<SchoolApi.AccountInfo>('/api/admin/school/saveAccount', data);
}

/**
 * 删除分校账号（仅超级管理员）
 * POST /api/admin/school/deleteAccount
 */
export async function deleteSchoolAccountApi(data: SchoolApi.DeleteAccountParams) {
  return requestClient.post('/api/admin/school/deleteAccount', data);
}

