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

from __future__ import annotations
from pydantic import model_serializer
from squadcast.types import BaseModel, UNSET_SENTINEL
from typing import Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


V3ServicesDeduplicationRulesExpressionBranchOp = Literal[
    "is",
    "is_not",
    "matches",
    "not_contains",
    "gt",
    "lt",
    "gt_eq",
    "lt_eq",
    "call",
    "field_is",
    "field_is_not",
    "field_gt",
    "field_lt",
    "field_gt_eq",
    "field_lt_eq",
]


V3ServicesDeduplicationRulesExpressionBranchRHSTypedDict = TypeAliasType(
    "V3ServicesDeduplicationRulesExpressionBranchRHSTypedDict",
    Union[str, bool, int, float],
)


V3ServicesDeduplicationRulesExpressionBranchRHS = TypeAliasType(
    "V3ServicesDeduplicationRulesExpressionBranchRHS", Union[str, bool, int, float]
)


class V3ServicesDeduplicationRulesExpressionBranchTypedDict(TypedDict):
    lhs: str
    rhs: V3ServicesDeduplicationRulesExpressionBranchRHSTypedDict
    op: NotRequired[V3ServicesDeduplicationRulesExpressionBranchOp]


class V3ServicesDeduplicationRulesExpressionBranch(BaseModel):
    lhs: str

    rhs: V3ServicesDeduplicationRulesExpressionBranchRHS

    op: Optional[V3ServicesDeduplicationRulesExpressionBranchOp] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["op"])
        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
