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

from __future__ import annotations
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 Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class IncomingMessageTypedDict(TypedDict):
    r"""An object with the properties of the received message"""

    id: NotRequired[int]
    r"""Unique identifier of incoming message"""
    login: NotRequired[str]
    r"""Login of the account (sub-account) on which the message was received"""
    recipient: NotRequired[str]
    r"""Recipient number (or service name)"""
    sender: NotRequired[str]
    r"""Message sender number (or alphanumeric name)"""
    phonebook_sender_name: NotRequired[Nullable[str]]
    r"""Sender name (matched with phonebook)"""
    date_: NotRequired[datetime]
    r"""Date and time of message receipt in ISO 8601 format"""
    message: NotRequired[str]
    r"""Received message content"""
    dedicated_number: NotRequired[Nullable[str]]
    r"""Dedicated Mobile Originated service number (if the message was received on this number)"""
    dedicated_prefix: NotRequired[Nullable[str]]
    r"""Dedicated Mobile Originated service prefix (if the message was received on this number with such prefix)"""


class IncomingMessage(BaseModel):
    r"""An object with the properties of the received message"""

    id: Optional[int] = None
    r"""Unique identifier of incoming message"""

    login: Optional[str] = None
    r"""Login of the account (sub-account) on which the message was received"""

    recipient: Optional[str] = None
    r"""Recipient number (or service name)"""

    sender: Optional[str] = None
    r"""Message sender number (or alphanumeric name)"""

    phonebook_sender_name: OptionalNullable[str] = UNSET
    r"""Sender name (matched with phonebook)"""

    date_: Annotated[Optional[datetime], pydantic.Field(alias="date")] = None
    r"""Date and time of message receipt in ISO 8601 format"""

    message: Optional[str] = None
    r"""Received message content"""

    dedicated_number: OptionalNullable[str] = UNSET
    r"""Dedicated Mobile Originated service number (if the message was received on this number)"""

    dedicated_prefix: OptionalNullable[str] = UNSET
    r"""Dedicated Mobile Originated service prefix (if the message was received on this number with such prefix)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "id",
            "login",
            "recipient",
            "sender",
            "phonebook_sender_name",
            "date",
            "message",
            "dedicated_number",
            "dedicated_prefix",
        ]
        nullable_fields = [
            "phonebook_sender_name",
            "dedicated_number",
            "dedicated_prefix",
        ]
        null_default_fields = []

        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
