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

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

export interface QueryParams {
  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;
}

export interface AddClassRes {
  status: boolean;
  msg: string;
  data: Record<string, unknown>;
  code: number;
}

export interface UserList {
  [index: string]: string;
}

export function editRequest(params: SelectConditionParams): Promise<Service.RequestResult<SelectConditionParams>> {
  return request.put(`/class/updateClass`, params);
}

export function pageRequest(
  pageNum: number,
  pageSize: number,
  params: SelectConditionParams
): Promise<Service.RequestResult<AddClassRes>> {
  return request.post(`/class/selectCondition?pageNum=${pageNum}&pageSize=${pageSize}`, params);
}

export function delRequest(id: number): Promise<Service.RequestResult<AddClassRes>> {
  return request.delete(`/class/deleteClass/${id}`);
}

export function addRequest(params: SelectConditionParams): Promise<Service.RequestResult<AddClassRes>> {
  return request.post(`/class/addClass`, params);
}

export async function queryAll(): Promise<UserList> {
  const ret: UserList = {};
  const respone: Service.RequestResult = await request.get(`/userinfo/queryAll`);
  respone.data?.map((result: QueryParams) => {
    ret[result.id] = result.relname;
    return result;
  });
  return ret;
}

/**
 * 查询所有的班级类
 * @param {string} classId
 * @returns
 */
export function queryClassStudentById(classId: number): Promise<Service.RequestResult<ClassStudentParams[]>> {
  return request.get(`/class/queryClassStudentByGroupId/${classId}`);
}

export interface ClassStudentParams {
  studentId: number;
}
export interface StudentRes {
  status: boolean;
  msg: string;
  data: Record<string, unknown>;
  code: number;
}

export interface StudentParams {
  id?: number;
  archiveNumber?: string;
  studentNumber?: string;
  studentName?: string;
  gender?: string;
  birthdate?: Record<string, unknown>;
  address?: string;
  phone?: string;
  email?: string;
  enrollmentDate?: Record<string, unknown>;
  graduationDate?: Record<string, unknown>;
  grade?: number;
  major?: string;
  minor?: string;
  university?: string;
  createTime?: Record<string, unknown>;
  modifyTime?: Record<string, unknown>;
  admissionsId?: number;
  managerId?: number;
  createUid?: number;
  studentIdnumber?: string;
}

export interface labelTransfer {
  label?: string;
  value?: number;
}

export function getAll(): Promise<Service.RequestResult<StudentParams[]>> {
  return request.get(`/student/getAll`);
}

export function submitGroupStudentForm(groupId: number, params?: number[]): Promise<Service.RequestResult<StudentRes>> {
  return request.post(`/class/groupStudent/${groupId}`, params);
}
