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

from __future__ import annotations
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 PatchWorkflowDtoTypedDict(TypedDict):
    active: NotRequired[bool]
    r"""Activate or deactivate the workflow"""
    name: NotRequired[str]
    r"""New name for the workflow"""
    description: NotRequired[str]
    r"""Updated description of the workflow"""
    tags: NotRequired[List[str]]
    r"""Tags associated with the workflow"""
    payload_schema: NotRequired[Nullable[Dict[str, Any]]]
    r"""The payload JSON Schema for the workflow"""
    validate_payload: NotRequired[bool]
    r"""Enable or disable payload schema validation"""
    is_translation_enabled: NotRequired[bool]
    r"""Enable or disable translations for this workflow"""


class PatchWorkflowDto(BaseModel):
    active: Optional[bool] = None
    r"""Activate or deactivate the workflow"""

    name: Optional[str] = None
    r"""New name for the workflow"""

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

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

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

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

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

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