"""Configuration for reservation/finalization billing integration."""

from pydantic import BaseModel, Field


class BillingConfig(BaseModel):
    """Configuration for external billing reservation/finalization calls."""

    enabled: bool = Field(default=False, description="Enable external billing middleware.")
    include_subagents: bool = Field(
        default=False,
        description="Whether billing applies to subagent model calls as well.",
    )
    fail_closed: bool = Field(
        default=True,
        description="Block model calls when reserve request fails or balance is insufficient.",
    )
    block_only_specific_reserve_codes: bool = Field(
        default=True,
        description=(
            "When true, only reserve responses with codes in blocking_reserve_codes block model calls. "
            "When false, fallback to fail_closed behavior for all reserve failures."
        ),
    )
    blocking_reserve_codes: list[int] = Field(
        default_factory=lambda: [-1104, -1106],
        description="Reserve response codes that should block model calls when block_only_specific_reserve_codes is enabled.",
    )
    frozen_type: int = Field(
        default=1,
        ge=1,
        description="Frozen type sent to the platform. Current flow uses 1 for token billing.",
    )
    reserve_url: str | None = Field(
        default=None,
        description="HTTP(S) endpoint for creating frozen reservations.",
    )
    finalize_url: str | None = Field(
        default=None,
        description="HTTP(S) endpoint for finalizing frozen reservations.",
    )
    headers: dict[str, str] = Field(
        default_factory=dict,
        description="Extra HTTP headers included in reserve/finalize requests.",
    )
    timeout_seconds: float = Field(
        default=10.0,
        gt=0,
        le=120,
        description="HTTP request timeout for reserve/finalize calls.",
    )
    default_expire_seconds: int = Field(
        default=1800,
        ge=60,
        le=86400,
        description="Default reservation expiration seconds when expireAt is included.",
    )
    default_estimated_output_tokens: int | None = Field(
        default=None,
        ge=1,
        description="Fallback estimatedOutputTokens when model max_tokens is unavailable.",
    )
