import { request } from '@/service/request';

// 参数接口
export interface ScheduleParams {
  id?: number;
  week: number;
  startTime: string | number;
  endTime: string | number;
  roomId: number | null;
  classId: number | null;
  assistantId: number | null;
  teacherId: number | null;
  categoryId: number | null;
  lessonTime?: number;
  subjectsId: number | null;
  createTime: number;
  modifyTime: number;
  createUid: number;
  disabled: string;
}

// 响应接口
export interface scheduleRes {
  status: boolean;
  msg: string;
  data: Record<string, unknown>;
  code: number;
}

/**
 * 添加课程表
 * @param {string} repeatTime
 * @param {object} params EasEduSchedule
 * @param {number} params.id
 * @param {number} params.week 当周周几
 * @param {object} params.startTime 起始时间
 * @param {object} params.endTime 结束时间
 * @param {number} params.roomId 教室ID
 * @param {number} params.classId 班级ID
 * @param {number} params.assistantId 助教ID
 * @param {number} params.teacherId 教师ID
 * @param {number} params.categoryId 授课类别
 * @param {number} params.subjectsId 授课内容
 * @param {object} params.createTime 创建时间
 * @param {object} params.modifyTime 修改时间
 * @param {number} params.createUid 创建用户ID
 * @param {string} params.disabled 状态
 * @returns
 */
export function addSchedule(repeatTime: number, params: ScheduleParams): Promise<Service.RequestResult<scheduleRes>> {
  return request.post(`/schedule/add?repeatTime=${repeatTime}`, params);
}

// 参数接口
export interface QueryConflictParams {
  startTime?: Record<string, unknown>;
  endTime?: Record<string, unknown>;
  roomId?: number;
  teacherId?: number;
}

/**
 * 查询排课是否冲突
 * @param {object} params ConflictDto
 * @param {object} params.startTime 课程开始时间
 * @param {object} params.endTime 课程结束时间
 * @param {number} params.roomId 教室ID
 * @param {number} params.teacherId 教师ID
 * @returns
 */
export function queryConflict(params: QueryConflictParams): Promise<Service.RequestResult<scheduleRes>> {
  return request.put(`/schedule/queryConflict`, params);
}

export interface UserParams {
  id?: number;
  username?: string;
  passwd?: string;
  email?: string;
  relname?: string;
  phone?: string;
  address?: string;
  createTime?: Record<string, unknown>;
  modifyTime?: Record<string, unknown>;
  createUid?: number;
  disabled?: string;
}

/**
 * 查询用户信息根据用户名
 * @param {string} realname
 * @returns
 */
export function queryByRealname(realname: string): Promise<Service.RequestResult<UserParams[]>> {
  return request.get(`/userinfo/queryUserByRealname/${realname}`);
}

export interface CategoryParams {
  id?: number;
  name?: string;
  description?: string;
  createTime?: Record<string, unknown>;
  modifyTime?: Record<string, unknown>;
  createUid?: number;
  disabled?: string;
}

/**
 * 根据条件进行查询课程类别
 * @param {string} pageNum
 * @param {string} pageSize
 * @param {object} params EasEduCategory
 * @param {number} params.id
 * @param {string} params.name 学科名称
 * @param {string} params.description 学科描述
 * @param {object} params.createTime 创建时间
 * @param {object} params.modifyTime 修改时间
 * @param {number} params.createUid 创建用户ID
 * @param {string} params.disabled 状态
 * @returns
 */
export function queryCategoryParams(
  pageNum: number,
  pageSize: number,
  params: CategoryParams
): Promise<Service.RequestResult<CategoryParams[]>> {
  return request.post(`/category/query?pageNum=${pageNum}&pageSize=${pageSize}`, params);
}

// 参数接口
export interface SubjectParams {
  id?: number;
  name?: string;
  description?: string;
  categoryId?: number;
  createTime?: Record<string, unknown>;
  modifyTime?: Record<string, unknown>;
  createUid?: number;
  disabled?: string;
}

/**
 * 根据条件进行查询课程
 * @param {string} pageNum
 * @param {string} pageSize
 * @param {object} params EasEduSubjects
 * @param {number} params.id
 * @param {string} params.name 学科名称
 * @param {string} params.description 学科描述
 * @param {number} params.categoryId 学科分类
 * @param {object} params.createTime 创建时间
 * @param {object} params.modifyTime 修改时间
 * @param {number} params.createUid 创建用户ID
 * @param {string} params.disabled 状态
 * @returns
 */
export function querySubject(
  pageNum: number,
  pageSize: number,
  params: SubjectParams
): Promise<Service.RequestResult<SubjectParams[]>> {
  return request.post(`/subject/query?pageNum=${pageNum}&pageSize=${pageSize}`, params);
}

export interface ClassParams {
  id?: number;
  name?: string;
  manageId?: number;
  assistantId?: number;
  createTime?: Record<string, unknown>;
  modifyTime?: Record<string, unknown>;
  createUid?: number;
  disabled?: string;
}

/**
 * 查询所有的班级类
 * @returns
 */
export function queryClassAll(): Promise<Service.RequestResult<ClassParams[]>> {
  return request.get(`/class/selectTotal`);
}

export interface ClassRoomParams {
  id?: number;
  name?: string;
  managerId?: number;
  address?: string;
  manager?: string;
  floor?: number;
  capacity?: number;
  comment?: string;
  disabled?: string;
  createTime?: Record<string, unknown>;
  modifyTime?: Record<string, unknown>;
  createUid?: number;
}

export function queryClassRoomList(
  pageNum: number,
  pageSize: number,
  params: ClassRoomParams
): Promise<Service.RequestResult<ClassRoomParams[]>> {
  return request.post(`/classroom/query?pageNum=${pageNum}&pageSize=${pageSize}`, params);
}

export interface ScheduleParamsList {
  id?: number;
  week?: number;
  startTime?: string;
  endTime?: string;
  roomId?: number | null;
  classId?: number | null;
  assistantId?: number | null;
  teacherId?: number | null;
  categoryId?: number | null;
  lessonTime?: number;
  subjectsId?: number | null;
  createTime?: number;
  modifyTime?: number;
  createUid?: number;
  disabled?: string;
  colspan?: number;
  empty?: boolean;
  break?: boolean;
}

export function queryScheduleList(
  pageNum: number,
  pageSize: number,
  params: ScheduleParamsList
): Promise<Service.RequestResult<ScheduleParamsList[]>> {
  return request.post(`/schedule/query?pageNum=${pageNum}&pageSize=${pageSize}`, params);
}

export function queryUserAll(): Promise<Service.RequestResult<UserParams[]>> {
  return request.get(`/userinfo/queryAll`);
}

export interface QueryScheduleParams {
  studentId?: number | null;
  classId?: number | null;
  subjectId?: number | null;
  teacherId?: number | null;
  startTime?: string | null;
  endTime?: string | null;
  week?: number | null;
  roomId?: number | null;
  assistantId?: number | null;
  categoryId?: number | null;
}

interface ScheduleResponse {
  id?: number;
  week?: number;
  startTime?: string;
  endTime?: string;
  roomId?: number;
  classroom?: string;
  classId?: number;
  assistantId?: number;
  assistantName?: string;
  teacherId?: number;
  teacherName?: string;
  categoryId?: number;
  category?: string;
  subjectsId?: number;
  subjects?: string;
  createTime?: string;
  modifyTime?: string;
  createUid?: number;
  disabled?: string;
}

export function querySchedule(params: QueryScheduleParams): Promise<Service.RequestResult<ScheduleResponse[]>> {
  return request.post(`/schedule/querySchedule`, params);
}

export interface EasSysStudentOptional {
  id?: number;
  studentNumber?: string;
  studentName?: string;
  gender?: string;
  phone?: string;
  email?: string;
  enrollmentDate?: Date;
  passwd?: string;
  avatar?: string;
  createTime?: Date;
  modifyTime?: Date;
  admissionsId?: number;
  managerId?: number;
  createUid?: number;
  disabled?: string;
}

/**
 * 查询所有学员信息
 * @param {string} keyword
 * @returns
 */
export function getStudentByKeyword(keyword: string): Promise<Service.RequestResult<EasSysStudentOptional[]>> {
  return request.get(`/student/getStudentByKeyword?keyword=${keyword}`);
}
