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

// 参数接口
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 interface Res {
  status: boolean;
  msg: string;
  data: Record<string, unknown>;
  code: number;
}

/**
 * 查询用户信息
 * @param {string} pageNum
 * @param {string} pageSize
 * @param {object} params EasSysUserinfo
 * @param {number} params.id 用户ID
 * @param {string} params.username 用户名
 * @param {string} params.passwd 密码
 * @param {string} params.email 电子邮件
 * @param {string} params.relname 姓名
 * @param {string} params.phone 电话
 * @param {string} params.address 地址
 * @param {object} params.createTime 创建时间
 * @param {object} params.modifyTime 修改时间
 * @param {number} params.createUid 创建用户ID
 * @param {string} params.disabled 状态
 * @returns
 */
export function queryUser(
  pageNum: number,
  pageSize: number,
  params: UserParams
): Promise<Service.RequestResult<UserParams[]>> {
  return request.post(`/userinfo/query?pageNum=${pageNum}&pageSize=${pageSize}`, params);
}

export function addUser(params: UserParams): Promise<Service.RequestResult<Res>> {
  return request.post(`/userinfo/add`, params);
}

export function updateUser(params: UserParams): Promise<Service.RequestResult<Res>> {
  return request.put(`/userinfo/update`, params);
}

export function deleteUser(id: number): Promise<Service.RequestResult<Res>> {
  return request.delete(`/userinfo/delete?id=${id}`);
}
