# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .budget_alert import BudgetAlert
from .budget_limit_unit import BudgetLimitUnit
from .budget_when import BudgetWhen


class BudgetRule(UniversalBaseModel):
    """
    Budget Rule
    """

    id: str = pydantic.Field()
    """
    Unique identifier for the rule
    """

    when: BudgetWhen
    limit_to: float = pydantic.Field()
    """
    Numeric limit value for the budget
    """

    unit: BudgetLimitUnit
    budget_applies_per: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Create separate budget rules for each unique value of the selected entity. For example, if "user" is selected, a separate budget rule will be created for each unique user making requests. Options: user, virtualaccount, model, or a metadata key (e.g., metadata.appId).
    """

    alerts: typing.Optional[BudgetAlert] = None

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow")  # type: ignore # Pydantic v2
    else:

        class Config:
            smart_union = True
            extra = pydantic.Extra.allow
