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

export namespace TeacherApi {
  /** 教师列表查询参数 */
  export interface ListParams {
    page?: number;
    limit?: number;
    teacher_id?: string;
    name?: string;
    department_id?: number;
    nickname?: string;
  }

  /** 教师信息 */
  export interface TeacherInfo {
    id?: number;
    teacher_id?: string | null;
    name?: string;
    gender?: string;
    department_id?: number;
    title?: string | null;
    phone?: string;
    email?: string;
    avatar?: string | null;
    remark?: string;
    status?: number;
    user_id?: number | null;
    create_time?: string;
    update_time?: string | null;
    nickname?: string;
    department_name?: string | null;
    classroom_count?: number;
    classroom_names?: string[];
    [key: string]: any;
  }

  /** 教师详情参数 */
  export interface DetailParams {
    id: number;
  }

  /** 保存教师参数 */
  export interface SaveParams extends TeacherInfo {
    id?: number;
  }

  /** 删除教师参数 */
  export interface DeleteParams {
    id: number;
  }
}

/**
 * 获取教师列表
 * GET /api/admin/teacher/list
 */
export async function getTeacherListApi(params?: TeacherApi.ListParams) {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/teacher/list', {
    params,
    responseReturn: 'body',
  });
}

/**
 * 获取教师详情
 * GET /api/admin/teacher/detail
 */
export async function getTeacherDetailApi(params: TeacherApi.DetailParams) {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/teacher/detail', {
    params,
    responseReturn: 'body',
  });
}

/**
 * 保存教师（新增/编辑）
 * POST /api/admin/teacher/save
 */
export async function saveTeacherApi(data: TeacherApi.SaveParams) {
  return requestClient.post<TeacherApi.TeacherInfo>('/api/admin/teacher/save', data);
}

/**
 * 删除教师
 * POST /api/admin/teacher/delete
 */
export async function deleteTeacherApi(data: TeacherApi.DeleteParams) {
  return requestClient.post('/api/admin/teacher/delete', data);
}

