import request from '@/utils/request';

export const listRole = (query) => {
  return request({
    url: '/api/v1/permission/roles',
    method: 'get',
    params: query
  });
};

/**
 * 查询角色详细
 */
export const getRole = (roleId) => {
  return request({
    url: '/api/v1/permission/roles/' + roleId,
    method: 'get'
  });
};

/**
 * 新增角色
 */
export const addRole = (data) => {
  return request({
    url: '/api/v1/permission/roles',
    method: 'post',
    data: data
  });
};

/**
 * 修改角色
 * @param data
 */
export const updateRole = (data) => {
  return request({
    url: '/api/v1/permission/roles/' + data.uid,
    method: 'put',
    data: data
  });
};

/**
 * 角色数据权限
 */
export const dataScope = (data) => {
  return request({
    url: '/system/role/dataScope',
    method: 'put',
    data: data
  });
};

/**
 * 角色状态修改
 */
export const changeRoleStatus = (roleId, status) => {
  const data = {
    roleId,
    status
  };
  return request({
    url: '/system/role/changeStatus',
    method: 'put',
    data: data
  });
};

/**
 * 删除角色
 */
export const delRole = (roleId) => {
  return request({
    url: '/api/v1/permission/roles/' + roleId,
    method: 'delete'
  });
};

/**
 * 查询用户已授权角色列表
 */
export const allocatedUserList = (query)=> {
  return request({
    url: '/api/v1/permission/users/' + query.userId + '/roles',
    method: 'get',
    params: query
  });
};

/**
 * 查询未分配角色列表
 */
export const unallocatedUserList = (query,userId) => {
  return request({ 
    url: '/api/v1/permission/users/' + userId + '/roles',
    method: 'get',
    params: query
  });
};

/**
 * 取消用户授权角色
 */
export const authUserCancel = (data) => { 
  return request({
    url: '/api/v1/permission/users/' + data.userId + '/roles/remove',
    method: 'post',
    data: data
  });
};

/**
 * 授权用户选择的角色
 */
export const authUserSelectAll = (data) => {  
  return request({
    url: '/api/v1/permission/users/' + data.userId + '/roles/add',
    method: 'post',
    data: data
  });
};
 
/**
 * 查询未分配用户角色列表
 */
// export const unallocatedUserList = (query) => {
//     return request({
//       url: '/api/v1/permission/roles',
//       method: 'get',
//       params: query
//     });
//   };