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

from __future__ import annotations
from .subscriptionpreferencedto import (
    SubscriptionPreferenceDto,
    SubscriptionPreferenceDtoTypedDict,
)
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 List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class SubscriberTypedDict(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 Subscriber(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 = set(["avatar", "firstName", "lastName", "email"])
        nullable_fields = set(["avatar", "firstName", "lastName", "email"])
        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


class SubscriptionResponseDtoTypedDict(TypedDict):
    id: str
    r"""The unique identifier of the subscription"""
    topic: TopicDtoTypedDict
    r"""The topic information"""
    subscriber: Nullable[SubscriberTypedDict]
    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"""
    name: NotRequired[str]
    r"""The name of the subscription"""
    preferences: NotRequired[List[SubscriptionPreferenceDtoTypedDict]]
    r"""The preferences for workflows in this subscription"""
    context_keys: NotRequired[List[str]]
    r"""Context keys that scope this subscription (e.g., tenant:org-a, project:proj-123)"""


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

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

    subscriber: Nullable[Subscriber]
    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"""

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

    preferences: Optional[List[SubscriptionPreferenceDto]] = None
    r"""The preferences for workflows in this subscription"""

    context_keys: Annotated[
        Optional[List[str]], pydantic.Field(alias="contextKeys")
    ] = None
    r"""Context keys that scope this subscription (e.g., tenant:org-a, project:proj-123)"""

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


try:
    Subscriber.model_rebuild()
except NameError:
    pass
try:
    SubscriptionResponseDto.model_rebuild()
except NameError:
    pass
