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

from __future__ import annotations
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from syllable_sdk.types import BaseModel, UNSET_SENTINEL
from syllable_sdk.utils import validate_const
from typing import Literal, Optional
from typing_extensions import Annotated, TypedDict


class CelExpressionTypedDict(TypedDict):
    r"""Google CEL expression object.

    Use this object form when you want CEL syntax:
    {\"type\": \"cel\", \"expression\": \"inputs.count + 1\"}
    See https://github.com/google/cel-spec/blob/master/doc/langdef.md
    """

    expression: str
    r"""CEL expression string."""
    type: Literal["cel"]
    r"""CEL expression language selector. Use with object form {\"type\":\"cel\",\"expression\":\"...\"}."""


class CelExpression(BaseModel):
    r"""Google CEL expression object.

    Use this object form when you want CEL syntax:
    {\"type\": \"cel\", \"expression\": \"inputs.count + 1\"}
    See https://github.com/google/cel-spec/blob/master/doc/langdef.md
    """

    expression: str
    r"""CEL expression string."""

    TYPE: Annotated[
        Annotated[Optional[Literal["cel"]], AfterValidator(validate_const("cel"))],
        pydantic.Field(alias="type"),
    ] = "cel"
    r"""CEL expression language selector. Use with object form {\"type\":\"cel\",\"expression\":\"...\"}."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["type"])
        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:
    CelExpression.model_rebuild()
except NameError:
    pass
