"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from openrouter.types import BaseModel, UnrecognizedStr
from openrouter.utils import validate_open_enum
from pydantic.functional_validators import PlainValidator
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


Logic = Union[
    Literal[
        "and",
        "or",
    ],
    UnrecognizedStr,
]


FieldT = Union[
    Literal[
        "model",
        "provider",
        "session_id",
        "user_id",
        "api_key_name",
        "finish_reason",
        "input",
        "output",
        "total_cost",
        "total_tokens",
        "prompt_tokens",
        "completion_tokens",
    ],
    UnrecognizedStr,
]


Operator = Union[
    Literal[
        "equals",
        "not_equals",
        "contains",
        "not_contains",
        "regex",
        "starts_with",
        "ends_with",
        "gt",
        "lt",
        "gte",
        "lte",
        "exists",
        "not_exists",
    ],
    UnrecognizedStr,
]


ObservabilityFilterRulesConfigValueTypedDict = TypeAliasType(
    "ObservabilityFilterRulesConfigValueTypedDict", Union[str, float]
)


ObservabilityFilterRulesConfigValue = TypeAliasType(
    "ObservabilityFilterRulesConfigValue", Union[str, float]
)


class RuleTypedDict(TypedDict):
    field: FieldT
    operator: Operator
    value: NotRequired[ObservabilityFilterRulesConfigValueTypedDict]


class Rule(BaseModel):
    field: Annotated[FieldT, PlainValidator(validate_open_enum(False))]

    operator: Annotated[Operator, PlainValidator(validate_open_enum(False))]

    value: Optional[ObservabilityFilterRulesConfigValue] = None


class GroupTypedDict(TypedDict):
    rules: List[RuleTypedDict]
    logic: NotRequired[Logic]


class Group(BaseModel):
    rules: List[Rule]

    logic: Annotated[Optional[Logic], PlainValidator(validate_open_enum(False))] = "and"


class ObservabilityFilterRulesConfigTypedDict(TypedDict):
    r"""Optional structured filter rules controlling which events are forwarded."""

    groups: List[GroupTypedDict]
    enabled: NotRequired[bool]


class ObservabilityFilterRulesConfig(BaseModel):
    r"""Optional structured filter rules controlling which events are forwarded."""

    groups: List[Group]

    enabled: Optional[bool] = True
