"""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 .resourceoriginenum import ResourceOriginEnum
from .severitylevelenum import SeverityLevelEnum
from .smsstepupsertdto import SmsStepUpsertDto, SmsStepUpsertDtoTypedDict
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


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


UpdateWorkflowDtoSteps = 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[CustomStepUpsertDto, Tag("custom")],
    ],
    Discriminator(lambda m: get_discriminator(m, "type", "type")),
]


class UpdateWorkflowDtoTypedDict(TypedDict):
    name: str
    r"""Name of the workflow"""
    steps: List[UpdateWorkflowDtoStepsTypedDict]
    r"""Steps of the workflow"""
    preferences: PreferencesRequestDtoTypedDict
    r"""Workflow preferences"""
    origin: ResourceOriginEnum
    r"""Origin of the layout"""
    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"""
    workflow_id: NotRequired[str]
    r"""Workflow ID (allowed only for code-first workflows)"""
    severity: NotRequired[SeverityLevelEnum]
    r"""Severity of the workflow"""


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

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

    preferences: PreferencesRequestDto
    r"""Workflow preferences"""

    origin: ResourceOriginEnum
    r"""Origin of the layout"""

    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"""

    workflow_id: Annotated[Optional[str], pydantic.Field(alias="workflowId")] = None
    r"""Workflow ID (allowed only for code-first workflows)"""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "description",
                "tags",
                "active",
                "validatePayload",
                "payloadSchema",
                "isTranslationEnabled",
                "workflowId",
                "severity",
            ]
        )
        nullable_fields = set(["payloadSchema"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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:
    UpdateWorkflowDto.model_rebuild()
except NameError:
    pass
