import request from '../index'
const prefix = 'sys'

// 角色查询
export function getRoleList(params: object) {
  return request({
    url: `${prefix}/role/list`,
    method: 'get',
    params,
  })
}
// 角色机构树列表
export function getRoleTreeList() {
  return request({
    url: `${prefix}/role/tree`,
    method: 'get',
  })
}
// 根据用户获取角色机构树列表
export function getRoleTreeListByUser(userId: string) {
  return request({
    url: `${prefix}/role/treeByUserId`,
    method: 'get',
    params: {
      userId,
    },
  })
}

// 添加角色机构
export function addRole(data: object) {
  return request({
    url: `${prefix}/role/add`,
    method: 'post',
    data,
  })
}
// 修改角色机构
export function updateRole(data: object) {
  return request({
    url: `${prefix}/role/update`,
    method: 'post',
    data,
  })
}
// 删除角色机构
export function delRole(id: string) {
  return request({
    url: `${prefix}/role/delete`,
    method: 'post',
    data: {
      id,
    },
  })
}

// 功能授权
export function funcAuthor(roleId: string, ids: string[]) {
  return request({
    url: 'sys/role/funcAuthor',
    method: 'post',
    data: {
      roleId,
      ids,
    },
  })
}
// 数据授权
export function dataAuthor(roleId: string, ids: string[]) {
  return request({
    url: `${prefix}/role/dataAuthor`,
    method: 'post',
    data: {
      roleId,
      ids,
    },
  })
}

// 角色类型列表
export function getDataScopeTypeList() {
  return request({
    url: `${prefix}/dict/code/dataScopeType`,
    method: 'get',
  })
}
