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

from __future__ import annotations
from .chatstepupsertdto import ChatStepUpsertDto, ChatStepUpsertDtoTypedDict
from .customstepupsertdto import CustomStepUpsertDto, CustomStepUpsertDtoTypedDict
from .delaystepupsertdto import DelayStepUpsertDto, DelayStepUpsertDtoTypedDict
from .digeststepupsertdto import DigestStepUpsertDto, DigestStepUpsertDtoTypedDict
from .emailstepupsertdto import EmailStepUpsertDto, EmailStepUpsertDtoTypedDict
from .inappstepupsertdto import InAppStepUpsertDto, InAppStepUpsertDtoTypedDict
from .preferencesrequestdto import PreferencesRequestDto, PreferencesRequestDtoTypedDict
from .pushstepupsertdto import PushStepUpsertDto, PushStepUpsertDtoTypedDict
from .severitylevelenum import SeverityLevelEnum
from .smsstepupsertdto import SmsStepUpsertDto, SmsStepUpsertDtoTypedDict
from .throttlestepupsertdto import ThrottleStepUpsertDto, ThrottleStepUpsertDtoTypedDict
from .workflowcreationsourceenum import WorkflowCreationSourceEnum
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from novu_py.utils import get_discriminator
import pydantic
from pydantic import Discriminator, Tag, model_serializer
from typing import Any, Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


StepsModelTypedDict = TypeAliasType(
    "StepsModelTypedDict",
    Union[
        InAppStepUpsertDtoTypedDict,
        EmailStepUpsertDtoTypedDict,
        SmsStepUpsertDtoTypedDict,
        PushStepUpsertDtoTypedDict,
        ChatStepUpsertDtoTypedDict,
        DelayStepUpsertDtoTypedDict,
        DigestStepUpsertDtoTypedDict,
        ThrottleStepUpsertDtoTypedDict,
        CustomStepUpsertDtoTypedDict,
    ],
)


StepsModel = Annotated[
    Union[
        Annotated[InAppStepUpsertDto, Tag("in_app")],
        Annotated[EmailStepUpsertDto, Tag("email")],
        Annotated[SmsStepUpsertDto, Tag("sms")],
        Annotated[PushStepUpsertDto, Tag("push")],
        Annotated[ChatStepUpsertDto, Tag("chat")],
        Annotated[DelayStepUpsertDto, Tag("delay")],
        Annotated[DigestStepUpsertDto, Tag("digest")],
        Annotated[ThrottleStepUpsertDto, Tag("throttle")],
        Annotated[CustomStepUpsertDto, Tag("custom")],
    ],
    Discriminator(lambda m: get_discriminator(m, "type", "type")),
]


class CreateWorkflowDtoTypedDict(TypedDict):
    name: str
    r"""Name of the workflow"""
    workflow_id: str
    r"""Unique identifier for the workflow"""
    steps: List[StepsModelTypedDict]
    r"""Steps of the workflow"""
    description: NotRequired[str]
    r"""Description of the workflow"""
    tags: NotRequired[List[str]]
    r"""Tags associated with the workflow"""
    active: NotRequired[bool]
    r"""Whether the workflow is active"""
    validate_payload: NotRequired[bool]
    r"""Enable or disable payload schema validation"""
    payload_schema: NotRequired[Nullable[Dict[str, Any]]]
    r"""The payload JSON Schema for the workflow"""
    is_translation_enabled: NotRequired[bool]
    r"""Enable or disable translations for this workflow"""
    source: NotRequired[WorkflowCreationSourceEnum]
    r"""Source of workflow creation"""
    preferences: NotRequired[PreferencesRequestDtoTypedDict]
    r"""Workflow preferences"""
    severity: NotRequired[SeverityLevelEnum]
    r"""Severity of the workflow"""


class CreateWorkflowDto(BaseModel):
    name: str
    r"""Name of the workflow"""

    workflow_id: Annotated[str, pydantic.Field(alias="workflowId")]
    r"""Unique identifier for the workflow"""

    steps: List[StepsModel]
    r"""Steps of the workflow"""

    description: Optional[str] = None
    r"""Description of the workflow"""

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

    active: Optional[bool] = False
    r"""Whether the workflow is active"""

    validate_payload: Annotated[
        Optional[bool], pydantic.Field(alias="validatePayload")
    ] = None
    r"""Enable or disable payload schema validation"""

    payload_schema: Annotated[
        OptionalNullable[Dict[str, Any]], pydantic.Field(alias="payloadSchema")
    ] = UNSET
    r"""The payload JSON Schema for the workflow"""

    is_translation_enabled: Annotated[
        Optional[bool], pydantic.Field(alias="isTranslationEnabled")
    ] = False
    r"""Enable or disable translations for this workflow"""

    source: Annotated[
        Optional[WorkflowCreationSourceEnum], pydantic.Field(alias="__source")
    ] = WorkflowCreationSourceEnum.EDITOR
    r"""Source of workflow creation"""

    preferences: Optional[PreferencesRequestDto] = None
    r"""Workflow preferences"""

    severity: Optional[SeverityLevelEnum] = None
    r"""Severity of the workflow"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "description",
            "tags",
            "active",
            "validatePayload",
            "payloadSchema",
            "isTranslationEnabled",
            "__source",
            "preferences",
            "severity",
        ]
        nullable_fields = ["payloadSchema"]
        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
