"""RBAC 路由控制器。"""

from typing import Any

from fastapi import Depends

from fastapi_common.fastapi_common_security.security import verify_access_token
from fastapi_common.fastapi_common_web.controller import BaseController
from fastapi_common.fastapi_common_web.domain.responses import Result

from fastapi_modules.fastapi_leaudit.domian.vo.rbacVo import RbacUserRoutesVO
from fastapi_modules.fastapi_leaudit.services import IRbacService
from fastapi_modules.fastapi_leaudit.services.impl.rbacServiceImpl import RbacServiceImpl


class RbacController(BaseController):
    """RBAC 路由控制器。"""

    def __init__(self):
        super().__init__(prefix="/rbac", tags=["RBAC"])
        self.RbacService: IRbacService = RbacServiceImpl()

        @self.router.get("/user/routes", response_model=Result[RbacUserRoutesVO])
        async def GetCurrentUserRoutes(payload: dict[str, Any] = Depends(verify_access_token)):
            """获取当前登录用户可访问的前端路由树。"""
            Data = await self.RbacService.GetCurrentUserRoutes(UserId=int(payload["user_id"]))
            return Result.success(data=Data)
