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

from __future__ import annotations
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Any, Dict
from typing_extensions import Annotated, NotRequired, TypedDict


class PatchSubscriberRequestDtoTypedDict(TypedDict):
    first_name: NotRequired[Nullable[str]]
    r"""First name of the subscriber"""
    last_name: NotRequired[Nullable[str]]
    r"""Last name of the subscriber"""
    email: NotRequired[Nullable[str]]
    r"""Email address of the subscriber"""
    phone: NotRequired[Nullable[str]]
    r"""Phone number of the subscriber"""
    avatar: NotRequired[Nullable[str]]
    r"""Avatar URL or identifier"""
    locale: NotRequired[Nullable[str]]
    r"""Locale of the subscriber"""
    timezone: NotRequired[Nullable[str]]
    r"""Timezone of the subscriber"""
    data: NotRequired[Nullable[Dict[str, Any]]]
    r"""Additional custom data associated with the subscriber"""


class PatchSubscriberRequestDto(BaseModel):
    first_name: Annotated[OptionalNullable[str], pydantic.Field(alias="firstName")] = (
        UNSET
    )
    r"""First name of the subscriber"""

    last_name: Annotated[OptionalNullable[str], pydantic.Field(alias="lastName")] = (
        UNSET
    )
    r"""Last name of the subscriber"""

    email: OptionalNullable[str] = UNSET
    r"""Email address of the subscriber"""

    phone: OptionalNullable[str] = UNSET
    r"""Phone number of the subscriber"""

    avatar: OptionalNullable[str] = UNSET
    r"""Avatar URL or identifier"""

    locale: OptionalNullable[str] = UNSET
    r"""Locale of the subscriber"""

    timezone: OptionalNullable[str] = UNSET
    r"""Timezone of the subscriber"""

    data: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Additional custom data associated with the subscriber"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "firstName",
                "lastName",
                "email",
                "phone",
                "avatar",
                "locale",
                "timezone",
                "data",
            ]
        )
        nullable_fields = set(
            [
                "firstName",
                "lastName",
                "email",
                "phone",
                "avatar",
                "locale",
                "timezone",
                "data",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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


try:
    PatchSubscriberRequestDto.model_rebuild()
except NameError:
    pass
