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

export interface QueryParams {
  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 interface QueryRes {
  status: boolean;
  msg: string;
  data: Record<string, unknown>;
  total: number;
}

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

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;
}

export function editRequest(params: QueryParams): Promise<Service.RequestResult<QueryParams>> {
  return request.put(`/classroom/update`, params);
}

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

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

export function addRequest(params: QueryParams): Promise<Service.RequestResult<QueryRes>> {
  return request.post(`/classroom/add`, params);
}

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