# #region PluginsRouter [C:3] [TYPE Module] [SEMANTICS fastapi, plugin, api]
# @BRIEF Defines the FastAPI router for plugin-related endpoints, allowing clients to list available plugins.
# @LAYER API
# @RELATION DEPENDS_ON -> [PluginConfig]
# @RELATION DEPENDS_ON -> [get_plugin_loader]
# @RELATION BINDS_TO -> [API_Routes]

from fastapi import APIRouter, Depends

from ...core.logger import belief_scope
from ...core.plugin_base import PluginConfig
from ...dependencies import get_plugin_loader, has_permission

router = APIRouter()


# #region list_plugins [TYPE Function]
# @BRIEF Retrieve a list of all available plugins.
# @PRE  plugin_loader is injected via Depends.
# @POST  Returns a list of PluginConfig objects.
# @RELATION CALLS -> [get_plugin_loader]
# @RELATION DEPENDS_ON -> [PluginConfig]
@router.get("", response_model=list[PluginConfig])
async def list_plugins(
    plugin_loader=Depends(get_plugin_loader),
    _=Depends(has_permission("plugins", "READ")),
):
    with belief_scope("list_plugins"):
        """
        Retrieve a list of all available plugins.
        """
        return plugin_loader.get_all_plugin_configs()


# #endregion list_plugins
# #endregion PluginsRouter
