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

from __future__ import annotations
from .topicdto import TopicDto, TopicDtoTypedDict
from novu_py.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 SubscriptionDtoSubscriberTypedDict(TypedDict):
    r"""The subscriber information"""

    id: str
    r"""The identifier of the subscriber"""
    subscriber_id: str
    r"""The external identifier of the subscriber"""
    avatar: NotRequired[Nullable[str]]
    r"""The avatar URL of the subscriber"""
    first_name: NotRequired[Nullable[str]]
    r"""The first name of the subscriber"""
    last_name: NotRequired[Nullable[str]]
    r"""The last name of the subscriber"""
    email: NotRequired[Nullable[str]]
    r"""The email of the subscriber"""


class SubscriptionDtoSubscriber(BaseModel):
    r"""The subscriber information"""

    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""The identifier of the subscriber"""

    subscriber_id: Annotated[str, pydantic.Field(alias="subscriberId")]
    r"""The external identifier of the subscriber"""

    avatar: OptionalNullable[str] = UNSET
    r"""The avatar URL of the subscriber"""

    first_name: Annotated[OptionalNullable[str], pydantic.Field(alias="firstName")] = (
        UNSET
    )
    r"""The first name of the subscriber"""

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["avatar", "firstName", "lastName", "email"]
        nullable_fields = ["avatar", "firstName", "lastName", "email"]
        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


class SubscriptionDtoTypedDict(TypedDict):
    id: str
    r"""The unique identifier of the subscription"""
    topic: TopicDtoTypedDict
    r"""The topic information"""
    subscriber: Nullable[SubscriptionDtoSubscriberTypedDict]
    r"""The subscriber information"""
    created_at: str
    r"""The creation date of the subscription"""
    updated_at: str
    r"""The last update date of the subscription"""
    identifier: NotRequired[str]
    r"""The identifier of the subscription"""


class SubscriptionDto(BaseModel):
    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""The unique identifier of the subscription"""

    topic: TopicDto
    r"""The topic information"""

    subscriber: Nullable[SubscriptionDtoSubscriber]
    r"""The subscriber information"""

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""The creation date of the subscription"""

    updated_at: Annotated[str, pydantic.Field(alias="updatedAt")]
    r"""The last update date of the subscription"""

    identifier: Optional[str] = None
    r"""The identifier of the subscription"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["identifier"]
        nullable_fields = ["subscriber"]
        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
