import { http } from '@/utils/http/axios';
import { PermissionTree, PermissionItem } from '@/types/permission/type';

/**
 * 获取整个功能权限树
 */
export function getPermissionTree() {
  return http.request<PermissionTree>({
    url: '/admin/perm/queryAllPermissionTree',
    method: 'post',
  });
}

/**
 * 获取当前用户拥有的功能权限树
 */
export function getOwnedPermissionTree() {
  return http.request<PermissionTree>({
    url: '/admin/perm/queryOwnedPermissionTree',
    method: 'post',
  });
}

/**
 * 添加权限
 */
export function addPermission(data: PermissionItem) {
  return http.request({
    url: '/admin/perm/savePermission',
    method: 'POST',
    data,
  });
}

/**
 * 修改权限
 */
export function updatePermission(data: PermissionItem) {
  return http.request({
    url: '/admin/perm/updatePermission',
    method: 'POST',
    data,
  });
}

/**
 * 删除权限
 */
export function deletePermission(permissionId: number) {
  return http.request({
    url: `/admin/perm/deletePermission?permId=${permissionId}`,
    method: 'POST',
  });
}
