# #region GitEnvironmentRoutes [C:2] [TYPE Module] [SEMANTICS fastapi, git, environment, api]
# @BRIEF FastAPI endpoint for listing deployment environments.
# @LAYER API


from fastapi import Depends

from src.api.routes.git_schemas import DeploymentEnvironmentSchema
from src.core.logger import belief_scope
from src.dependencies import get_config_manager, has_permission

from ._router import router


# #region get_environments [C:2] [TYPE Function]
# @BRIEF List all deployment environments.
@router.get("/environments", response_model=list[DeploymentEnvironmentSchema])
async def get_environments(
    config_manager=Depends(get_config_manager),
    _=Depends(has_permission("environments", "READ")),
):
    with belief_scope("get_environments"):
        envs = config_manager.get_environments()
        return [
            DeploymentEnvironmentSchema(
                id=e.id, name=e.name, superset_url=e.url, is_active=True
            )
            for e in envs
        ]
# #endregion get_environments
# #endregion GitEnvironmentRoutes
