import { RoleVO, RoleQuery, RoleBO, RoleMenuVO, RoleMenuBO, RolePermBO, RolePermVO } from '@/api/interface/system/role'
import http from '@/axios'

class RoleApi {
  /**
   * 获取角色列表
   * @param params
   * @returns {*}
   */
  static page = (params: RoleQuery): Promise<ResultData<any>> => {
    return http.get<ResPage<RoleVO>>({ url: '/system/role/page', params })
  }

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

  /**
   * @name 添加
   * @returns returns
   */
  static add = (data: RoleBO): Promise<ResultData<any>> => {
    return http.post({ url: '/system/role/add', data })
  }
  /**
   * @name 更新
   * @returns returns
   */
  static edit = (data: RoleBO): Promise<ResultData<any>> => {
    return http.put({ url: '/system/role/edit', data })
  }

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

  /**
   * @name 查询已有菜单
   * @returns returns
   */
  static getMenu = (roleId: string): Promise<ResultData<any>> => {
    return http.get<RoleMenuVO>({ url: `/system/role/menu/${roleId}` })
  }

  /**
   * @name 用户添加角色
   * @returns returns
   */
  static addMenu = (data: RoleMenuBO): Promise<ResultData<any>> => {
    return http.put({ url: `/system/role/menu/add`, data })
  }

  /**
   * @name 查询已有权限点
   * @returns returns
   */
  static getPermissions = (permId: string): Promise<ResultData<any>> => {
    return http.get<RolePermVO>({ url: `/system/role/permission/${permId}` })
  }

  /**
   * @name 角色添加权限点
   * @returns returns
   */
  static addPermission = (data: RolePermBO): Promise<ResultData<any>> => {
    return http.put({ url: `/system/role/permission/add`, data })
  }
}
export default RoleApi
