from __future__ import annotations

from typing import Optional

from pydantic import BaseModel, Field


class RateLimits(BaseModel):
    rpm: Optional[int] = Field(default=None, description="Requests per minute")
    tpm: Optional[int] = Field(default=None, description="Tokens per minute (aggregate)")
    itpm: Optional[int] = Field(default=None, description="Input tokens per minute (Anthropic)")
    otpm: Optional[int] = Field(default=None, description="Output tokens per minute (Anthropic)")
    concurrency: Optional[int] = Field(default=None, description="Max in-flight requests")


class ModelOverride(BaseModel):
    provider: str
    model: str
    limits: RateLimits


class TierPlan(BaseModel):
    name: str
    description: Optional[str] = None
    defaults: RateLimits
    overrides: list[ModelOverride] = Field(default_factory=list)


class OrgAssignment(BaseModel):
    org_id: str
    tier: str


class TakumiConfig(BaseModel):
    version: str = "v1"
    tiers: list[TierPlan]
    orgs: list[OrgAssignment] = Field(default_factory=list)
