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

from __future__ import annotations
from .steptypeenum import StepTypeEnum
from .workfloworiginenum import WorkflowOriginEnum
from .workflowstatusenum import WorkflowStatusEnum
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 WorkflowListResponseDtoTypedDict(TypedDict):
    name: str
    r"""Name of the workflow"""
    updated_at: str
    r"""Last updated timestamp"""
    created_at: str
    r"""Creation timestamp"""
    id: str
    r"""Unique database identifier"""
    workflow_id: str
    r"""Workflow identifier"""
    slug: str
    r"""Workflow slug"""
    status: WorkflowStatusEnum
    r"""Status of the workflow"""
    origin: WorkflowOriginEnum
    r"""Origin of the workflow"""
    step_type_overviews: List[StepTypeEnum]
    r"""Overview of step types in the workflow"""
    tags: NotRequired[List[str]]
    r"""Tags associated with the workflow"""
    last_triggered_at: NotRequired[Nullable[str]]
    r"""Timestamp of the last workflow trigger"""


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

    updated_at: Annotated[str, pydantic.Field(alias="updatedAt")]
    r"""Last updated timestamp"""

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""Creation timestamp"""

    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""Unique database identifier"""

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

    slug: str
    r"""Workflow slug"""

    status: WorkflowStatusEnum
    r"""Status of the workflow"""

    origin: WorkflowOriginEnum
    r"""Origin of the workflow"""

    step_type_overviews: Annotated[
        List[StepTypeEnum], pydantic.Field(alias="stepTypeOverviews")
    ]
    r"""Overview of step types in the workflow"""

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

    last_triggered_at: Annotated[
        OptionalNullable[str], pydantic.Field(alias="lastTriggeredAt")
    ] = UNSET
    r"""Timestamp of the last workflow trigger"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["tags", "lastTriggeredAt"]
        nullable_fields = ["lastTriggeredAt"]
        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
