import http from '@/axios'
import { PasswordBO, UserBO, UserInfo, UserQuery, UserRoleBO, UserRoleVO, UserVO } from '@/api/interface/system/user'

class UserApi {
  static getInfo = (): Promise<ResultData<any>> => {
    return http.get<UserInfo[]>({ url: '/system/user/info' })
  }

  /**
   * @name 查询分页
   * @returns returns
   */
  static page = (params: UserQuery): Promise<ResultData<any>> => {
    return http.get<UserVO>({ url: '/system/user/page', params })
  }

  /**
   * @name 查询列表
   * @returns returns
   */
  static list = (params: UserBO): Promise<ResultData<any>> => {
    return http.get<UserVO>({ url: '/system/user/list', params })
  }

  /**
   * @name 添加
   * @returns returns
   */
  static add = (data: UserBO): Promise<ResultData<any>> => {
    return http.post({ url: '/system/user/add', data })
  }

  /**
   * @name 更新
   * @returns returns
   */
  static edit = (data: UserBO): Promise<ResultData<any>> => {
    return http.put({ url: '/system/user/edit', data })
  }

  /**
   * @name 修改密码
   * @returns returns
   */
  static modifyPassword = (data: PasswordBO): Promise<ResultData<any>> => {
    return http.put({ url: '/system/user/password/modify', data })
  }

  /**
   * @name 重置密码
   * @returns returns
   */
  static resetPassword = (data: string): Promise<ResultData<any>> => {
    return http.put({ url: '/system/user/password/reset', data })
  }

  /**
   * @name 删除
   * @returns returns
   */
  static delete = (data: string[]): Promise<ResultData<any>> => {
    return http.delete({ url: '/system/user/delete', data })
  }

  /**
   * @name 查询已有角色
   * @returns returns
   */
  static getRole = (userId: string): Promise<ResultData<any>> => {
    return http.get<UserRoleVO>({ url: `/system/user/role/${userId}` })
  }

  /**
   * @name 用户添加角色
   * @returns returns
   */
  static addRole = (data: UserRoleBO): Promise<ResultData<any>> => {
    return http.put({ url: `/system/user/role/add`, data })
  }
}
export default UserApi
