import { request } from '@/service/request';

// 获取角色列表
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/system/role/list',
    method: 'get',
    params
  });
}

// 获取角色详情
export function fetchGetRole(roleId: string | number) {
  return request<Api.SystemManage.Role>({
    url: `/system/role/${roleId}`,
    method: 'get'
  });
}

// 新增角色
export function fetchAddRole(data: Api.SystemManage.Role) {
  return request({
    url: '/system/role',
    method: 'post',
    data
  });
}

// 修改角色
export function fetchEditRole(data: Api.SystemManage.Role) {
  return request({
    url: '/system/role',
    method: 'put',
    data
  });
}

// 删除角色
export function fetchDeleteRole(roleIds: Api.SystemManage.Role['roleId'][]) {
  return request({
    url: `/system/role/${roleIds}`,
    method: 'delete'
  });
}

// 角色状态修改
export function changeRoleStatus(roleId: Api.SystemManage.Role['roleId'], status: Api.SystemManage.Role['status']) {
  return request({
    url: '/system/role/changeStatus',
    method: 'put',
    data: {
      roleId,
      status
    }
  });
}

// 根据角色ID查询部门树结构
export function roleDeptTreeselect(roleId: Api.SystemManage.Role['roleId']) {
  return request({
    url: `/system/role/deptTree/${roleId}`,
    method: 'get'
  });
}

// 角色数据权限
export function dataScope(data: Api.SystemManage.Role) {
  return request({
    url: '/system/role/dataScope',
    method: 'put',
    data
  });
}

// 查询角色已授权用户列表
export function allocatedUserList(query: Api.SystemManage.UserSearchParams) {
  return request({
    url: '/system/role/authUser/allocatedList',
    method: 'get',
    params: query
  });
}

// 查询角色未授权用户列表
export function unallocatedUserList(query: Api.SystemManage.UserSearchParams) {
  return request({
    url: '/system/role/authUser/unallocatedList',
    method: 'get',
    params: query
  });
}

// 取消用户授权角色
export function authUserCancel(data: {
  roleId: Api.SystemManage.Role['roleId'];
  userId: Api.SystemManage.User['userId'];
}) {
  return request({
    url: '/system/role/authUser/cancel',
    method: 'put',
    data
  });
}

// 批量取消用户授权角色
export function authUserCancelAll(data: { roleId: Api.SystemManage.Role['roleId']; userIds: string }) {
  return request({
    url: '/system/role/authUser/cancelAll',
    method: 'put',
    params: data
  });
}

// 授权用户选择
export function authUserSelectAll(data: { roleId: Api.SystemManage.Role['roleId']; userIds: string }) {
  return request({
    url: '/system/role/authUser/selectAll',
    method: 'put',
    params: data
  });
}
