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

from __future__ import annotations
from .emailcontrolsmetadataresponsedto import (
    EmailControlsMetadataResponseDto,
    EmailControlsMetadataResponseDtoTypedDict,
)
from .resourceoriginenum import ResourceOriginEnum
from .stepissuesdto import StepIssuesDto, StepIssuesDtoTypedDict
from .steptypeenum import StepTypeEnum
from enum import Enum
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import ConfigDict, model_serializer
from typing import Any, Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class EmailStepResponseDtoEditorType(str, Enum):
    r"""Type of editor to use for the body."""

    BLOCK = "block"
    HTML = "html"


class EmailStepResponseDtoControlValuesTypedDict(TypedDict):
    r"""Control values for the email step"""

    subject: str
    r"""Subject of the email."""
    skip: NotRequired[Dict[str, Any]]
    r"""JSONLogic filter conditions for conditionally skipping the step execution. Supports complex logical operations with AND, OR, and comparison operators. See https://jsonlogic.com/ for full typing reference."""
    body: NotRequired[str]
    r"""Body content of the email, either a valid Maily JSON object, or html string."""
    editor_type: NotRequired[EmailStepResponseDtoEditorType]
    r"""Type of editor to use for the body."""
    disable_output_sanitization: NotRequired[bool]
    r"""Disable sanitization of the output."""
    layout_id: NotRequired[Nullable[str]]
    r"""Layout ID to use for the email. Null means no layout, undefined means default layout."""


class EmailStepResponseDtoControlValues(BaseModel):
    r"""Control values for the email step"""

    model_config = ConfigDict(
        populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
    )
    __pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)

    subject: str
    r"""Subject of the email."""

    skip: Optional[Dict[str, Any]] = None
    r"""JSONLogic filter conditions for conditionally skipping the step execution. Supports complex logical operations with AND, OR, and comparison operators. See https://jsonlogic.com/ for full typing reference."""

    body: Optional[str] = ""
    r"""Body content of the email, either a valid Maily JSON object, or html string."""

    editor_type: Annotated[
        Optional[EmailStepResponseDtoEditorType], pydantic.Field(alias="editorType")
    ] = EmailStepResponseDtoEditorType.BLOCK
    r"""Type of editor to use for the body."""

    disable_output_sanitization: Annotated[
        Optional[bool], pydantic.Field(alias="disableOutputSanitization")
    ] = False
    r"""Disable sanitization of the output."""

    layout_id: Annotated[OptionalNullable[str], pydantic.Field(alias="layoutId")] = (
        UNSET
    )
    r"""Layout ID to use for the email. Null means no layout, undefined means default layout."""

    @property
    def additional_properties(self):
        return self.__pydantic_extra__

    @additional_properties.setter
    def additional_properties(self, value):
        self.__pydantic_extra__ = value  # pyright: ignore[reportIncompatibleVariableOverride]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "skip",
            "body",
            "editorType",
            "disableOutputSanitization",
            "layoutId",
        ]
        nullable_fields = ["layoutId"]
        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

        for k, v in serialized.items():
            m[k] = v

        return m


class EmailStepResponseDtoTypedDict(TypedDict):
    controls: EmailControlsMetadataResponseDtoTypedDict
    r"""Controls metadata for the email step"""
    variables: Dict[str, Any]
    r"""JSON Schema for variables, follows the JSON Schema standard"""
    step_id: str
    r"""Unique identifier of the step"""
    id: str
    r"""Database identifier of the step"""
    name: str
    r"""Name of the step"""
    slug: str
    r"""Slug of the step"""
    type: StepTypeEnum
    r"""Type of the step"""
    origin: ResourceOriginEnum
    r"""Origin of the layout"""
    workflow_id: str
    r"""Workflow identifier"""
    workflow_database_id: str
    r"""Workflow database identifier"""
    control_values: NotRequired[EmailStepResponseDtoControlValuesTypedDict]
    r"""Control values for the email step"""
    issues: NotRequired[StepIssuesDtoTypedDict]
    r"""Issues associated with the step"""


class EmailStepResponseDto(BaseModel):
    controls: EmailControlsMetadataResponseDto
    r"""Controls metadata for the email step"""

    variables: Dict[str, Any]
    r"""JSON Schema for variables, follows the JSON Schema standard"""

    step_id: Annotated[str, pydantic.Field(alias="stepId")]
    r"""Unique identifier of the step"""

    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""Database identifier of the step"""

    name: str
    r"""Name of the step"""

    slug: str
    r"""Slug of the step"""

    type: StepTypeEnum
    r"""Type of the step"""

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

    workflow_id: Annotated[str, pydantic.Field(alias="workflowId")]
    r"""Workflow identifier"""

    workflow_database_id: Annotated[str, pydantic.Field(alias="workflowDatabaseId")]
    r"""Workflow database identifier"""

    control_values: Annotated[
        Optional[EmailStepResponseDtoControlValues],
        pydantic.Field(alias="controlValues"),
    ] = None
    r"""Control values for the email step"""

    issues: Optional[StepIssuesDto] = None
    r"""Issues associated with the step"""
