from __future__ import annotations from typing import Any from fastapi import APIRouter from sqlalchemy import select from bid_doctor.billing import service from bid_doctor.billing.models import Plan from bid_doctor.core.db import anonymous_tx, tenant_tx from bid_doctor.identity.deps import Ctx router = APIRouter(tags=["billing"]) @router.get("/plans") async def list_plans() -> dict[str, Any]: async with anonymous_tx() as s: plans = (await s.execute(select(Plan).where(Plan.active).order_by(Plan.code))).scalars().all() return { "items": [ {"code": p.code, "version": p.version, "name": p.name, "quotas": p.quotas, "limits": p.limits} for p in plans ] } @router.get("/quota") async def get_quota(ctx: Ctx) -> dict[str, Any]: async with tenant_tx(ctx) as s: return await service.overview(s, ctx)