"""Ping endpoint — useful for clients to validate their key + network."""
from typing import Annotated

from fastapi import APIRouter, Depends, Request
from pydantic import BaseModel

from app.auth.api_key_auth import require_api_key
from app.rate_limit import limiter

router = APIRouter(tags=["public-api"])


class HealthResponse(BaseModel):
    ok: bool
    label: str
    version: str


@router.get(
    "/health",
    response_model=HealthResponse,
    summary="Ping / key validation",
    description=(
        "Returns 200 if the supplied `X-API-Key` is active, with the "
        "label of the key you're using. Handy as a smoke test before "
        "wiring up a production client."
    ),
)
@limiter.limit("60/minute")
async def health(
    request: Request,
    key: Annotated[dict, Depends(require_api_key)],
) -> HealthResponse:
    return HealthResponse(ok=True, label=key["label"], version="v1")
