from __future__ import annotations

from fastapi import APIRouter, Depends, Query, Request

from backend.auth.dependencies import UserPrincipal, get_current_user
from backend.observability import metrics_snapshot

router = APIRouter(prefix="/observability", tags=["Observability"])


@router.get("/request-metrics")
async def request_metrics(
    request: Request,
    limit: int = Query(default=50, ge=1, le=200),
    user: UserPrincipal = Depends(get_current_user),
) -> dict:
    return {
        "status": "ok",
        "data": {
            "tenant_id": user.tenant_id,
            "metrics": metrics_snapshot(request.app, limit=limit),
        },
    }

