/**
 * KRA - Casbin API Service
 */
import request from '@/utils/request';
import type { ApiResponse } from '@/types/api';

export interface CasbinInfo {
  path: string;
  method: string;
}

/** 更新角色API权限 */
export const updateCasbin = (data: { authorityId: number | string; casbinInfos: CasbinInfo[] }) => {
  return request.post<ApiResponse<any>>('/casbin/updateCasbin', {
    ...data,
    authorityId: Number(data.authorityId),
  });
};

/** 获取角色API权限列表 */
export const getPolicyPathByAuthorityId = (data: { authorityId: number | string }) => {
  return request.post<ApiResponse<{ paths: CasbinInfo[] }>>('/casbin/getPolicyPathByAuthorityId', {
    authorityId: Number(data.authorityId),
  });
};

export default {
  updateCasbin,
  getPolicyPathByAuthorityId,
};
