import request from "@/utils/request";
import { RoleDTO } from "./role";

class UserAPI {
  /**
   * 获取用户分页列表
   *
   * @param queryParams 查询参数
   */
  static getPage(queryParams: PageQuery) {
    return request<any, PageResult<UserPageVO[]>>({
      url: `/api/user/getUserPage`,
      method: "get",
      params: queryParams,
    });
  }

  /**
   * 添加用户
   *
   * @param data 用户表单数据
   */
  static add(data: UserForm) {
    return request<any, string>({
      url: `/api/user/addUser`,
      method: "post",
      data: data,
    });
  }

  /**
   * 修改用户
   *
   * @param id 用户ID
   * @param data 用户表单数据
   */
  static updateUserById(data: UserForm) {
    return request({
      url: `/api/user/updateUserById`,
      method: "post",
      data: data,
    });
  }

  /**
   * 批量删除用户，多个以英文逗号(,)分割
   *
   * @param ids 用户ID字符串，多个以英文逗号(,)分割
   */
  static updateUserByIdOffline(data: { id: number }) {
    return request<any, string>({
      url: `/api/user/updateUserByIdOffline`,
      method: "post",
      data: data,
    });
  }

  /**
   * 获取用户信息
   */

  static getUserInfo() {
    return request<any, any>({
      url: `/api/user/getUserInfo`,
      method: "GET",
    });
  }
}

export default UserAPI;

/**
 * 用户分页查询对象
 */
export interface UserPageQuery extends PageQuery {
  /** 搜索关键字 */
  name?: string;
  phone?: string;
  roleId?: number;
}

/** 用户分页对象 */
export interface UserPageVO {
  areaId?: string;
  cardCode?: string;
  citiyId?: string;
  createTime?: string;
  createUserId?: number;
  createUserName?: string;
  factoryAddress?: string;
  factoryName?: string;
  gender?: number;
  id: number;
  isDeleted?: string;
  name?: string;
  password?: string;
  phone?: string;
  provinceId?: string;
  roleVos?: RoleDTO[];
  state?: number;
  updateTime?: string;
  updateUserId?: number;
  updateUserName?: string;
  userName?: string;
  userType?: number;
}

/** 用户表单类型 */
export interface UserForm {
  userType?: number;
  gender?: number;
  name?: string;
  roleName?: string;
  roleIds?: number[];
  phone?: string;
  id?: number;
  roleId?: number;
}
