Source code for qfa.api.schemas_usage

"""HTTP-layer wrappers over the domain usage stats.

ADR-007 keeps API and domain models separate where the API needs to
hide internal fields or reshape the wire format. The usage endpoints
don't need either — the domain ``TenantUsageStats`` *is* the aggregate the
consumer wants. The only HTTP-specific addition is the echoed
``from``/``to`` query window, so this module holds two thin wrappers
that add those fields and nothing else.
"""

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

from qfa.domain.usage_models import OperationUsageStats, TenantUsageStats


[docs] class UsageStatsResponse(TenantUsageStats): """Domain ``TenantUsageStats`` plus echoed ``from``/``to`` query bounds.""" model_config = ConfigDict(frozen=True, populate_by_name=True) from_: datetime | None = Field(default=None, alias="from") to: datetime | None = None
[docs] class AllUsageStatsResponse(BaseModel): """Per-tenant + grand total usage with optional echoed time window.""" model_config = ConfigDict(populate_by_name=True) from_: datetime | None = Field(default=None, alias="from") to: datetime | None = None tenants: list[TenantUsageStats] total: TenantUsageStats
[docs] class AllUsageByOperationResponse(BaseModel): """Per-operation + grand total usage with optional echoed time window. Inverse hierarchy of :class:`AllUsageStatsResponse`: ``operations`` is the list of per-operation blocks (each with a nested ``tenants`` breakdown), and ``total`` is the cross-operation grand total (``operation`` is null). """ model_config = ConfigDict(populate_by_name=True) from_: datetime | None = Field(default=None, alias="from") to: datetime | None = None operations: list[OperationUsageStats] total: OperationUsageStats