import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { RoleQuery, RoleForm } from './types';

//获取所有角色
export function listRolePages(queryParams:any){
  return request({
    url: '/system/role/list' ,
    method: 'post',
    params:queryParams
  });
}
//角色是否有效
export function isvaildTo(queryParams:any){
  return request({
    url: '/system/role/setIsvaild' ,
    method: 'post',
    params:queryParams
  });
}
//新增角色
export function addDept(queryParams:any){
  return request({
    url:'/system/role/addRole' ,
    method: 'post',
    data: queryParams
  });
}
//更新角色信息
export function renewDept (queryParams:any){
  return request({
    url:'/system/role/updateById' ,
    method: 'post',
    data: queryParams
  });
}
//单个删除角色
export function deleDept (queryParams:any){
  return request({
    url:'/system/role/deleteById' ,
    method: 'post',
    params: queryParams
  });
}

//获取分配权限
export function assignmentPer (queryParams:any){
  return request({
    url:'/system/menu/permissionAssignment' ,
    method: 'post',
    params: queryParams
  });
}
//发出分配权限
export function setMenuById (queryParams:any){
  return request({
    url:'/system/role/setMenuById' ,
    method: 'post',
    params: queryParams
  });
}
////获取组织范围
export function setOrgscope (queryParams:any){
  return request({
    url:'/system/organization/getOrgScopeTree' ,
    method: 'post',
    params: queryParams
  });
}
//修改组织范围
export function postOrgscope (queryParams:any){
  return request({
    url:'/system/role/setOrgscope' ,
    method: 'post',
    params: queryParams
  });
}


//删除角色
// export function delDept(queryParams:any){
//   return request({
//     url:'/system/role/addRole' ,
//     method: 'post',
//     data: queryParams
//   });
// }

/**
 * 获取角色分页数据
 *
 * @param queryParam
 */
// export function listRolePages(
//   queryParams?: RoleQuery
// ): AxiosPromise<RolePageResult> {
//   return request({
//     url: '/system/role/list',
//     method: 'post',
//     params: queryParams
//   });
// }

/**
 * 获取角色下拉数据
 *
 * @param queryParams
 */
export function listRoleOptions(
  queryParams?: RoleQuery
): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/v1/roles/options',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取角色拥有的资源ID集合
 *
 * @param queryParams
 */
export function getRoleMenuIds(roleId: string): AxiosPromise<number[]> {
  return request({
    url: '/api/v1/roles/' + roleId + '/menuIds',
    method: 'get'
  });
}

/**
 * 修改角色资源权限
 *
 * @param queryParams
 */
export function updateRoleMenus(
  roleId: string,
  data: number[]
): AxiosPromise<any> {
  return request({
    url: '/api/v1/roles/' + roleId + '/menus',
    method: 'put',
    data: data
  });
}

/**
 * 获取角色详情
 *
 * @param id
 */
export function getRoleDetail(id: number): AxiosPromise<RoleForm> {
  return request({
    url: '/api/v1/roles/' + id,
    method: 'get'
  });
}

/**
 * 添加角色
 *
 * @param data
 */
export function addRole(data: RoleForm) {
  return request({
    url: '/api/v1/roles',
    method: 'post',
    data: data
  });
}

/**
 * 更新角色
 *
 * @param id
 * @param data
 */
export function updateRole(id: number, data: RoleForm) {
  return request({
    url: '/api/v1/roles/' + id,
    method: 'put',
    data: data
  });
}

/**
 * 批量删除角色，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteRoles(ids: string) {
  return request({
    url: '/api/v1/roles/' + ids,
    method: 'delete'
  });
}
