from uuid import UUID

from fastapi import APIRouter, Depends

from app.api.deps import AsyncSession, CurrentUser, get_current_user, get_db, require_tenant
from app.api.permissions import require_permissions
from app.permissions.definitions import MONITORING_VIEW
from app.schemas.common import MonitoringStatsOut
from app.services.monitoring_service import MonitoringService

router = APIRouter()


@router.get("/stats", response_model=MonitoringStatsOut)
async def monitoring_stats(
    tenant_id: UUID = Depends(require_tenant),
    session: AsyncSession = Depends(get_db),
    _: CurrentUser = Depends(require_permissions(MONITORING_VIEW)),
):
    return await MonitoringService(session).stats(tenant_id)


@router.get("/metrics")
async def monitoring_metrics(
    tenant_id: UUID = Depends(require_tenant),
    session: AsyncSession = Depends(get_db),
    _: CurrentUser = Depends(require_permissions(MONITORING_VIEW)),
):
    return await MonitoringService(session).metrics(tenant_id)
