"""Health check endpoint."""

import platform
from typing import Any

from fastapi import APIRouter, Request

from .. import __version__
from ..auth import auth_enabled
from ..config import settings

router = APIRouter(prefix="/api", tags=["health"])


@router.get("/health")
async def health_check(request: Request) -> dict[str, Any]:
    """Health check endpoint - no authentication required.

    Returns:
        Health status and server information
    """
    result: dict[str, Any] = {
        "status": "healthy",
        "platform": platform.system(),
        "version": __version__,
        "auth_required": auth_enabled(),
        "media_folders_management": settings.media_folders_management,
    }

    # Include cached update info if available
    checker = getattr(request.app.state, "update_checker", None)
    if checker is not None and checker.cached_update is not None:
        result["update_available"] = checker.cached_update

    return result
