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

from __future__ import annotations
from .subscriberdto import SubscriberDto, SubscriberDtoTypedDict
from .topicresponsedto import TopicResponseDto, TopicResponseDtoTypedDict
from novu_py.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class TopicSubscriptionResponseDtoTypedDict(TypedDict):
    id: str
    r"""The identifier of the subscription"""
    identifier: str
    r"""The identifier of the subscription"""
    created_at: str
    r"""The date and time the subscription was created"""
    topic: TopicResponseDtoTypedDict
    r"""Topic information"""
    subscriber: SubscriberDtoTypedDict
    r"""Subscriber information"""
    context_keys: NotRequired[List[str]]
    r"""Context keys that scope this subscription (e.g., tenant:org-a, project:proj-123)"""


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

    identifier: str
    r"""The identifier of the subscription"""

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""The date and time the subscription was created"""

    topic: TopicResponseDto
    r"""Topic information"""

    subscriber: SubscriberDto
    r"""Subscriber information"""

    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(["contextKeys"])
        serialized = handler(self)
        m = {}

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    TopicSubscriptionResponseDto.model_rebuild()
except NameError:
    pass
