import {
  AddRoleParams,
  BaseListResult,
  BaseResult,
  EditPDAMenuParams,
  EditRoleMenuParams,
  EditRoleParams,
  GetRoleListParams,
  RoleListData,
} from '@models';
import {request} from './request';

const BASE_URL = '/role';

/** 获取角色列表 */
export function getRoleList(params: GetRoleListParams): BaseListResult<RoleListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getRole`,
    data: params,
  });
}

/** 删除角色 */
export function deleteRole(id: string): BaseResult {
  return request({
    method: 'DELETE',
    url: `${BASE_URL}/delRole`,
    data: {id},
  });
}

/** 新增角色 */
export function addRole(params: AddRoleParams): BaseResult {
  return request({
    method: 'POST',
    data: params,
    url: `${BASE_URL}/addRole`,
  });
}

/** 修改角色 */
export function editRole(params: EditRoleParams): BaseResult {
  return request({
    method: 'PUT',
    data: params,
    url: `${BASE_URL}/updateRole`,
  });
}

/** 导出角色 */
export function exportRole(params: GetRoleListParams): any {
  return request({
    method: 'GET',
    data: params,
    url: `${BASE_URL}/export`,
    skipError: true,
  });
}

/** 修改角色菜单权限 */
export function editRoleMenu(params: EditRoleMenuParams): BaseResult {
  return request({
    method: 'PUT',
    data: params,
    url: `${BASE_URL}/updateRole`,
  });
}

/** 修改角色PDA菜单权限 */
export function editRolePDAMenu(params: EditPDAMenuParams): BaseResult {
  return request({
    method: 'PUT',
    data: params,
    url: `${BASE_URL}/updateRole`,
  });
}

/** 查询所有角色 */
export function getAllRoleList(): BaseResult<RoleListData[]> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/roleBefore`,
    skipError: true,
  });
}

/** 获取角色详情 */
export function getRoleInfo(id: string): BaseListResult<RoleListData> {
  return request({
    method: 'GET',
    url: `${BASE_URL}/getRole`,
    data: {id, page: '1', limit: '1'},
  });
}
