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

from __future__ import annotations
from .preferencelevelenum import PreferenceLevelEnum
from .severitylevelenum import SeverityLevelEnum
from .subscriberpreferencechannels import (
    SubscriberPreferenceChannels,
    SubscriberPreferenceChannelsTypedDict,
)
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


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


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


class WorkflowTypedDict(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[GetPreferencesResponseDtoDataTypedDict]
    r"""Custom data associated with the workflow"""


class Workflow(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[GetPreferencesResponseDtoData] = None
    r"""Custom data associated with the workflow"""

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

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

        return m


class ConditionTypedDict(TypedDict):
    r"""Condition using JSON Logic rules"""


class Condition(BaseModel):
    r"""Condition using JSON Logic rules"""


class GetPreferencesResponseDtoTypedDict(TypedDict):
    level: PreferenceLevelEnum
    r"""The level of the preference (global or template)"""
    enabled: bool
    r"""Whether the preference is enabled"""
    channels: SubscriberPreferenceChannelsTypedDict
    r"""Channel-specific preference settings"""
    workflow: NotRequired[Nullable[WorkflowTypedDict]]
    r"""Workflow information if this is a template-level preference"""
    condition: NotRequired[Nullable[ConditionTypedDict]]
    r"""Condition using JSON Logic rules"""


class GetPreferencesResponseDto(BaseModel):
    level: PreferenceLevelEnum
    r"""The level of the preference (global or template)"""

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

    channels: SubscriberPreferenceChannels
    r"""Channel-specific preference settings"""

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

    condition: OptionalNullable[Condition] = UNSET
    r"""Condition using JSON Logic rules"""

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