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

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


class SubscriptionPreferenceDtoDataTypedDict(TypedDict):
    r"""Custom data associated with the workflow"""


class SubscriptionPreferenceDtoData(BaseModel):
    r"""Custom data associated with the workflow"""


class SubscriptionPreferenceDtoWorkflowTypedDict(TypedDict):
    r"""Workflow information if this is a template-level preference"""

    id: str
    r"""Unique identifier of the workflow"""
    identifier: str
    r"""Workflow identifier used for triggering"""
    name: str
    r"""Human-readable name of the workflow"""
    critical: bool
    r"""Whether this workflow is marked as critical"""
    severity: SeverityLevelEnum
    r"""Severity of the workflow"""
    tags: NotRequired[List[str]]
    r"""Tags associated with the workflow"""
    data: NotRequired[SubscriptionPreferenceDtoDataTypedDict]
    r"""Custom data associated with the workflow"""


class SubscriptionPreferenceDtoWorkflow(BaseModel):
    r"""Workflow information if this is a template-level preference"""

    id: str
    r"""Unique identifier of the workflow"""

    identifier: str
    r"""Workflow identifier used for triggering"""

    name: str
    r"""Human-readable name of the workflow"""

    critical: bool
    r"""Whether this workflow is marked as critical"""

    severity: SeverityLevelEnum
    r"""Severity of the workflow"""

    tags: Optional[List[str]] = None
    r"""Tags associated with the workflow"""

    data: Optional[SubscriptionPreferenceDtoData] = None
    r"""Custom data associated with the workflow"""


class SubscriptionPreferenceDtoTypedDict(TypedDict):
    subscription_id: str
    r"""The unique identifier of the subscription"""
    enabled: bool
    r"""Whether the preference is enabled"""
    workflow: NotRequired[Nullable[SubscriptionPreferenceDtoWorkflowTypedDict]]
    r"""Workflow information if this is a template-level preference"""
    condition: NotRequired[Dict[str, Any]]
    r"""Optional condition using JSON Logic rules"""


class SubscriptionPreferenceDto(BaseModel):
    subscription_id: Annotated[str, pydantic.Field(alias="subscriptionId")]
    r"""The unique identifier of the subscription"""

    enabled: bool
    r"""Whether the preference is enabled"""

    workflow: OptionalNullable[SubscriptionPreferenceDtoWorkflow] = UNSET
    r"""Workflow information if this is a template-level preference"""

    condition: Optional[Dict[str, Any]] = None
    r"""Optional condition using JSON Logic rules"""

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