from fastapi import APIRouter, Request
from pydantic import BaseModel

router = APIRouter(tags=["health"])


class HealthResponse(BaseModel):
    status: str
    environment: str
    components: dict[str, str]


@router.get("/health", response_model=HealthResponse)
def health(request: Request) -> HealthResponse:
    database_status = request.app.state.container.database_status.get()
    return HealthResponse(
        status="ok" if database_status.available else "degraded",
        environment=request.app.state.settings.environment,
        components={
            "process": "ok",
            "database": "ok" if database_status.available else "unavailable",
        },
    )
