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

from __future__ import annotations
from .rulecondition import RuleCondition, RuleConditionTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateRuleRequestTypedDict(TypedDict):
    conditions: List[RuleConditionTypedDict]
    r"""Conditions that must ALL be met (AND logic) for auto-acceptance. Sample values: customerEmail domain='@trusted.com' AND amount lessThan=1000, customerId equals='org_abc123' AND billableMetricId equals='bm_tokens', subscriptionId equals='sub_xyz789' AND quantity greaterThan=100"""
    name: str
    r"""Human-readable name for the source rule"""
    source_id: str
    r"""Unique identifier for a source"""
    description: NotRequired[str]
    r"""Detailed description of what this source rule does"""
    enabled: NotRequired[bool]
    r"""Whether this rule should be active immediately"""
    order: NotRequired[int]
    r"""Evaluation priority (0-999). Lower numbers are evaluated first. First matching rule triggers auto-acceptance."""


class CreateRuleRequest(BaseModel):
    conditions: List[RuleCondition]
    r"""Conditions that must ALL be met (AND logic) for auto-acceptance. Sample values: customerEmail domain='@trusted.com' AND amount lessThan=1000, customerId equals='org_abc123' AND billableMetricId equals='bm_tokens', subscriptionId equals='sub_xyz789' AND quantity greaterThan=100"""

    name: str
    r"""Human-readable name for the source rule"""

    source_id: Annotated[str, pydantic.Field(alias="sourceId")]
    r"""Unique identifier for a source"""

    description: Optional[str] = None
    r"""Detailed description of what this source rule does"""

    enabled: Optional[bool] = True
    r"""Whether this rule should be active immediately"""

    order: Optional[int] = 0
    r"""Evaluation priority (0-999). Lower numbers are evaluated first. First matching rule triggers auto-acceptance."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["description", "enabled", "order"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    CreateRuleRequest.model_rebuild()
except NameError:
    pass
