"""Liveness (no auth) + authenticated status for the client's connection test."""
from __future__ import annotations

from fastapi import APIRouter, Depends

from .. import enhance as enhance_mod
from ..auth import Principal
from ..config import ServerConfig
from ..deps import AuthDep, get_config, get_engine
from ..engine import EngineHost

router = APIRouter()


@router.get("/healthz")
async def healthz() -> dict:
    """Unauthenticated liveness probe (Docker/systemd/load balancer)."""
    return {"ok": True}


@router.get("/v1/status")
async def status(
    principal: Principal = AuthDep,
    engine: EngineHost = Depends(get_engine),
    config: ServerConfig = Depends(get_config),
) -> dict:
    """Full server status: version, readiness, active + available models, GPU.
    Backs the client's 'Test connection' button and model picker. The `enhance`
    block advertises central AI enhancement WITHOUT exposing the key."""
    data = engine.status()
    data["enhance"] = {
        "available": enhance_mod.is_available(config),
        "provider": enhance_mod.provider_of(config),
    }
    return data
