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

export namespace ClassApi {
  /** 班级列表查询参数 */
  export interface ListParams {
    page?: number;
    limit?: number;
    name?: string;
    teacher_name?: string;
    school_id?: number;
  }

  /** 班级信息 */
  export interface ClassInfo {
    id?: number;
    name?: string;
    grade?: string;
    department_id?: number;
    teacher_id?: number;
    student_count?: number;
    class_room_id?: number;
    description?: string;
    status?: number;
    create_time?: string;
    update_time?: string;
    teacher?: {
      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;
    };
    classroom?: {
      id?: number;
      name?: string;
      location?: string;
      teacher_id?: number;
      type?: string;
      capacity?: number;
      layout?: string;
      status?: number;
      description?: string;
      create_time?: string;
      update_time?: string;
      layout_cols?: number;
      layout_rows?: number;
      fiexd_start_time?: string;
      fiexd_end_time?: string;
      view_images?: string;
      school_id?: number;
      school?: any;
    };
    [key: string]: any;
  }

  /** 保存班级参数 */
  export interface SaveParams extends ClassInfo {
    id?: number;
  }

  /** 删除班级参数 */
  export interface DeleteParams {
    id: number;
  }

  /** 班级详情参数 */
  export interface DetailParams {
    id: number;
  }
}

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

/**
 * 获取班主任列表
 * GET /api/admin/classmanager/getTeachers
 */
export async function getTeachersApi() {
  // 使用 responseReturn: 'body' 获取完整响应体，支持可能的 code/data 格式
  return requestClient.get<any>('/api/admin/classmanager/getTeachers', {
    responseReturn: 'body',
  });
}

/**
 * 获取教室列表
 * GET /api/admin/classmanager/getClassrooms
 */
export async function getClassroomsApi() {
  // 使用 responseReturn: 'body' 获取完整响应体，支持可能的 code/data 格式
  return requestClient.get<any>('/api/admin/classmanager/getClassrooms', {
    responseReturn: 'body',
  });
}

/**
 * 获取班级详情
 * GET /api/admin/classmanager/detail
 */
export async function getClassDetailApi(params: ClassApi.DetailParams) {
  // 使用 responseReturn: 'body' 获取完整响应体
  return requestClient.get<any>('/api/admin/classmanager/detail', {
    params,
    responseReturn: 'body',
  });
}

/**
 * 保存班级（新增/编辑）
 * POST /api/admin/classmanager/save
 */
export async function saveClassApi(data: ClassApi.SaveParams) {
  return requestClient.post<ClassApi.ClassInfo>('/api/admin/classmanager/save', data);
}

/**
 * 删除班级
 * POST /api/admin/classmanager/deleteClass
 */
export async function deleteClassApi(data: ClassApi.DeleteParams) {
  return requestClient.post('/api/admin/classmanager/deleteClass', data);
}

