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

from __future__ import annotations
from .phonenumberwithcid import PhoneNumberWithCid, PhoneNumberWithCidTypedDict
from datetime import datetime
from gsmservice_gateway.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


RecipientsTypedDict = TypeAliasType(
    "RecipientsTypedDict",
    Union[
        PhoneNumberWithCidTypedDict, str, List[str], List[PhoneNumberWithCidTypedDict]
    ],
)
r"""The recipient number or multiple recipients numbers of single message. To set one recipient, simply pass a `str` with his phone number. To set multiple recipients, please pass `List[str]`. Optionally you can also set custom id (user identifier) for each message - pass `PhoneNumberWithCid` object (in case of single recipient) or List[PhoneNumberWithCid] (in case of multiple recipients)."""


Recipients = TypeAliasType(
    "Recipients", Union[PhoneNumberWithCid, str, List[str], List[PhoneNumberWithCid]]
)
r"""The recipient number or multiple recipients numbers of single message. To set one recipient, simply pass a `str` with his phone number. To set multiple recipients, please pass `List[str]`. Optionally you can also set custom id (user identifier) for each message - pass `PhoneNumberWithCid` object (in case of single recipient) or List[PhoneNumberWithCid] (in case of multiple recipients)."""


AttachmentsTypedDict = TypeAliasType("AttachmentsTypedDict", Union[str, List[str]])
r"""Attachments for the message. You can pass here images, audio and video files bodies. To set one attachment please pass a `str` with attachment body encoded with `base64`. To set multiple attachments - pass `List[str]` with attachments bodies encoded with `base64`. Max 3 attachments per message."""


Attachments = TypeAliasType("Attachments", Union[str, List[str]])
r"""Attachments for the message. You can pass here images, audio and video files bodies. To set one attachment please pass a `str` with attachment body encoded with `base64`. To set multiple attachments - pass `List[str]` with attachments bodies encoded with `base64`. Max 3 attachments per message."""


class MmsMessageTypedDict(TypedDict):
    r"""An object with a new MMS message properties"""

    recipients: RecipientsTypedDict
    r"""The recipient number or multiple recipients numbers of single message. To set one recipient, simply pass a `str` with his phone number. To set multiple recipients, please pass `List[str]`. Optionally you can also set custom id (user identifier) for each message - pass `PhoneNumberWithCid` object (in case of single recipient) or List[PhoneNumberWithCid] (in case of multiple recipients)."""
    subject: NotRequired[Nullable[str]]
    r"""MMS message subject"""
    message: NotRequired[Nullable[str]]
    r"""MMS message content"""
    attachments: NotRequired[AttachmentsTypedDict]
    r"""Attachments for the message. You can pass here images, audio and video files bodies. To set one attachment please pass a `str` with attachment body encoded with `base64`. To set multiple attachments - pass `List[str]` with attachments bodies encoded with `base64`. Max 3 attachments per message."""
    date_: NotRequired[Nullable[datetime]]
    r"""Scheduled future date and time of sending the message (in ISO 8601 format). If missing or null - message will be sent immediately"""


class MmsMessage(BaseModel):
    r"""An object with a new MMS message properties"""

    recipients: Recipients
    r"""The recipient number or multiple recipients numbers of single message. To set one recipient, simply pass a `str` with his phone number. To set multiple recipients, please pass `List[str]`. Optionally you can also set custom id (user identifier) for each message - pass `PhoneNumberWithCid` object (in case of single recipient) or List[PhoneNumberWithCid] (in case of multiple recipients)."""

    subject: OptionalNullable[str] = UNSET
    r"""MMS message subject"""

    message: OptionalNullable[str] = UNSET
    r"""MMS message content"""

    attachments: Optional[Attachments] = None
    r"""Attachments for the message. You can pass here images, audio and video files bodies. To set one attachment please pass a `str` with attachment body encoded with `base64`. To set multiple attachments - pass `List[str]` with attachments bodies encoded with `base64`. Max 3 attachments per message."""

    date_: Annotated[OptionalNullable[datetime], pydantic.Field(alias="date")] = None
    r"""Scheduled future date and time of sending the message (in ISO 8601 format). If missing or null - message will be sent immediately"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["subject", "message", "attachments", "date"]
        nullable_fields = ["subject", "message", "date"]
        null_default_fields = ["date"]

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
