"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 0fd96a7c058b

from __future__ import annotations
from .encodedpayloadoptions import EncodedPayloadOptions
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import ConfigDict, model_serializer
from typing import Any, Dict, List, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


class SignalInvocationBodyNetworkEncodedInputTypedDict(TypedDict):
    b64payload: str
    r"""The encoded payload"""
    encoding_options: NotRequired[List[EncodedPayloadOptions]]
    r"""The encoding of the payload"""
    empty: NotRequired[bool]
    r"""Whether the payload is empty"""


class SignalInvocationBodyNetworkEncodedInput(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
    )
    __pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)

    b64payload: str
    r"""The encoded payload"""

    encoding_options: Optional[List[EncodedPayloadOptions]] = None
    r"""The encoding of the payload"""

    empty: Optional[bool] = False
    r"""Whether the payload is empty"""

    @property
    def additional_properties(self):
        return self.__pydantic_extra__

    @additional_properties.setter
    def additional_properties(self, value):
        self.__pydantic_extra__ = value  # pyright: ignore[reportIncompatibleVariableOverride]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["encoding_options", "empty"])
        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))
            serialized.pop(k, serialized.pop(n, None))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val
        for k, v in serialized.items():
            m[k] = v

        return m


SignalInvocationBodyInputTypedDict = TypeAliasType(
    "SignalInvocationBodyInputTypedDict",
    Union[SignalInvocationBodyNetworkEncodedInputTypedDict, Dict[str, Any]],
)
r"""Input data for the signal, matching its schema"""


SignalInvocationBodyInput = TypeAliasType(
    "SignalInvocationBodyInput",
    Union[SignalInvocationBodyNetworkEncodedInput, Dict[str, Any]],
)
r"""Input data for the signal, matching its schema"""


class SignalInvocationBodyTypedDict(TypedDict):
    name: str
    r"""The name of the signal to send"""
    input: NotRequired[Nullable[SignalInvocationBodyInputTypedDict]]
    r"""Input data for the signal, matching its schema"""


class SignalInvocationBody(BaseModel):
    name: str
    r"""The name of the signal to send"""

    input: OptionalNullable[SignalInvocationBodyInput] = UNSET
    r"""Input data for the signal, matching its schema"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["input"])
        nullable_fields = set(["input"])
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
