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

from __future__ import annotations
from .messagetemplatedto import MessageTemplateDto, MessageTemplateDtoTypedDict
from .stepfilterdto import StepFilterDto, StepFilterDtoTypedDict
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ActivityNotificationStepResponseDtoReplyCallbackTypedDict(TypedDict):
    r"""Reply callback settings"""


class ActivityNotificationStepResponseDtoReplyCallback(BaseModel):
    r"""Reply callback settings"""


class ControlVariablesTypedDict(TypedDict):
    r"""Control variables"""


class ControlVariables(BaseModel):
    r"""Control variables"""


class ActivityNotificationStepResponseDtoMetadataTypedDict(TypedDict):
    r"""Metadata for the workflow step"""


class ActivityNotificationStepResponseDtoMetadata(BaseModel):
    r"""Metadata for the workflow step"""


class IssuesTypedDict(TypedDict):
    r"""Step issues"""


class Issues(BaseModel):
    r"""Step issues"""


class ActivityNotificationStepResponseDtoTypedDict(TypedDict):
    id: str
    r"""Unique identifier of the step"""
    active: bool
    r"""Whether the step is active or not"""
    filters: List[StepFilterDtoTypedDict]
    r"""Filter criteria for the step"""
    template_id: str
    r"""The identifier for the template associated with this step"""
    reply_callback: NotRequired[
        ActivityNotificationStepResponseDtoReplyCallbackTypedDict
    ]
    r"""Reply callback settings"""
    control_variables: NotRequired[ControlVariablesTypedDict]
    r"""Control variables"""
    metadata: NotRequired[ActivityNotificationStepResponseDtoMetadataTypedDict]
    r"""Metadata for the workflow step"""
    issues: NotRequired[IssuesTypedDict]
    r"""Step issues"""
    template: NotRequired[MessageTemplateDtoTypedDict]
    r"""Optional template for the step"""
    variants: NotRequired[List[ActivityNotificationStepResponseDtoTypedDict]]
    r"""Variants of the step"""
    name: NotRequired[str]
    r"""The name of the step"""
    parent_id: NotRequired[Nullable[str]]
    r"""The unique identifier for the parent step"""


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

    active: bool
    r"""Whether the step is active or not"""

    filters: List[StepFilterDto]
    r"""Filter criteria for the step"""

    template_id: Annotated[str, pydantic.Field(alias="_templateId")]
    r"""The identifier for the template associated with this step"""

    reply_callback: Annotated[
        Optional[ActivityNotificationStepResponseDtoReplyCallback],
        pydantic.Field(alias="replyCallback"),
    ] = None
    r"""Reply callback settings"""

    control_variables: Annotated[
        Optional[ControlVariables], pydantic.Field(alias="controlVariables")
    ] = None
    r"""Control variables"""

    metadata: Optional[ActivityNotificationStepResponseDtoMetadata] = None
    r"""Metadata for the workflow step"""

    issues: Optional[Issues] = None
    r"""Step issues"""

    template: Optional[MessageTemplateDto] = None
    r"""Optional template for the step"""

    variants: Optional[List[ActivityNotificationStepResponseDto]] = None
    r"""Variants of the step"""

    name: Optional[str] = None
    r"""The name of the step"""

    parent_id: Annotated[OptionalNullable[str], pydantic.Field(alias="_parentId")] = (
        UNSET
    )
    r"""The unique identifier for the parent step"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "replyCallback",
            "controlVariables",
            "metadata",
            "issues",
            "template",
            "variants",
            "name",
            "_parentId",
        ]
        nullable_fields = ["_parentId"]
        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
