"""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
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class UpdateRuleRequestTypedDict(TypedDict):
    conditions: NotRequired[List[RuleConditionTypedDict]]
    r"""List of conditions that must ALL be met (AND logic)"""
    description: NotRequired[str]
    r"""Detailed description of what this source rule does"""
    enabled: NotRequired[bool]
    r"""Whether this rule should be active"""
    name: NotRequired[str]
    r"""Human-readable name for the source rule"""
    order: NotRequired[int]
    r"""Priority order for rule evaluation (lower numbers are evaluated first)"""


class UpdateRuleRequest(BaseModel):
    conditions: Optional[List[RuleCondition]] = None
    r"""List of conditions that must ALL be met (AND logic)"""

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

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

    name: Optional[str] = None
    r"""Human-readable name for the source rule"""

    order: Optional[int] = None
    r"""Priority order for rule evaluation (lower numbers are evaluated first)"""

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

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

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

        return m
