"""Endpoint سلامت سرویس."""
from __future__ import annotations

from fastapi import APIRouter

from app import __version__
from app.core.cache import cache
from app.core.config import settings
from app.schemas.common import HealthResponse

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


@router.get("/health", response_model=HealthResponse)
async def health() -> HealthResponse:
    """بررسی سلامت سرویس و وابستگی‌ها (Redis)."""
    redis_ok = await cache.ping()
    return HealthResponse(
        status="ok",
        service=settings.service_name,
        version=__version__,
        environment=settings.environment,
        dependencies={"redis": "ok" if redis_ok else "unavailable"},
    )
