"""
Health check router
"""

import logging
from fastapi import APIRouter
from ..schemas import HealthResponse
from .. import dependencies

logger = logging.getLogger(__name__)
router = APIRouter()


@router.get("/health", response_model=HealthResponse)
async def health_check():
    """
    Health check endpoint

    Returns service status and Groq API client initialization status
    """
    try:
        predictor = dependencies.model_predictor

        if predictor is None:
            return HealthResponse(
                status="unhealthy",
                model_loaded=False,
                adapters_loaded=[]
            )

        return HealthResponse(
            status="healthy",
            model_loaded=predictor.is_loaded(),
            adapters_loaded=predictor.get_loaded_adapters()
        )
    except Exception as e:
        logger.error(f"Health check failed: {e}", exc_info=True)
        return HealthResponse(
            status="unhealthy",
            model_loaded=False,
            adapters_loaded=[]
        )

