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

from __future__ import annotations
from .resourceoriginenum import ResourceOriginEnum
from .steplistresponsedto import StepListResponseDto, StepListResponseDtoTypedDict
from .steptypeenum import StepTypeEnum
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 WorkflowListResponseDtoUpdatedByTypedDict(TypedDict):
    r"""User who last updated the workflow"""

    id: str
    r"""User ID"""
    first_name: NotRequired[Nullable[str]]
    r"""User first name"""
    last_name: NotRequired[Nullable[str]]
    r"""User last name"""
    external_id: NotRequired[Nullable[str]]
    r"""User external ID"""


class WorkflowListResponseDtoUpdatedBy(BaseModel):
    r"""User who last updated the workflow"""

    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""User ID"""

    first_name: Annotated[OptionalNullable[str], pydantic.Field(alias="firstName")] = (
        UNSET
    )
    r"""User first name"""

    last_name: Annotated[OptionalNullable[str], pydantic.Field(alias="lastName")] = (
        UNSET
    )
    r"""User last name"""

    external_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="externalId")
    ] = UNSET
    r"""User external ID"""

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


class WorkflowListResponseDtoLastPublishedByTypedDict(TypedDict):
    r"""User who last published the workflow"""

    id: str
    r"""User ID"""
    first_name: NotRequired[Nullable[str]]
    r"""User first name"""
    last_name: NotRequired[Nullable[str]]
    r"""User last name"""
    external_id: NotRequired[Nullable[str]]
    r"""User external ID"""


class WorkflowListResponseDtoLastPublishedBy(BaseModel):
    r"""User who last published the workflow"""

    id: Annotated[str, pydantic.Field(alias="_id")]
    r"""User ID"""

    first_name: Annotated[OptionalNullable[str], pydantic.Field(alias="firstName")] = (
        UNSET
    )
    r"""User first name"""

    last_name: Annotated[OptionalNullable[str], pydantic.Field(alias="lastName")] = (
        UNSET
    )
    r"""User last name"""

    external_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="externalId")
    ] = UNSET
    r"""User external ID"""

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


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: ResourceOriginEnum
    r"""Origin of the layout"""
    step_type_overviews: List[StepTypeEnum]
    r"""Overview of step types in the workflow"""
    steps: List[StepListResponseDtoTypedDict]
    r"""Steps of the workflow"""
    tags: NotRequired[List[str]]
    r"""Tags associated with the workflow"""
    updated_by: NotRequired[Nullable[WorkflowListResponseDtoUpdatedByTypedDict]]
    r"""User who last updated the workflow"""
    last_published_at: NotRequired[Nullable[str]]
    r"""Timestamp of the last workflow publication"""
    last_published_by: NotRequired[
        Nullable[WorkflowListResponseDtoLastPublishedByTypedDict]
    ]
    r"""User who last published the workflow"""
    last_triggered_at: NotRequired[Nullable[str]]
    r"""Timestamp of the last workflow trigger"""
    is_translation_enabled: NotRequired[bool]
    r"""Is translation enabled for the workflow"""


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: ResourceOriginEnum
    r"""Origin of the layout"""

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

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

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

    updated_by: Annotated[
        OptionalNullable[WorkflowListResponseDtoUpdatedBy],
        pydantic.Field(alias="updatedBy"),
    ] = UNSET
    r"""User who last updated the workflow"""

    last_published_at: Annotated[
        OptionalNullable[str], pydantic.Field(alias="lastPublishedAt")
    ] = UNSET
    r"""Timestamp of the last workflow publication"""

    last_published_by: Annotated[
        OptionalNullable[WorkflowListResponseDtoLastPublishedBy],
        pydantic.Field(alias="lastPublishedBy"),
    ] = UNSET
    r"""User who last published the workflow"""

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

    is_translation_enabled: Annotated[
        Optional[bool], pydantic.Field(alias="isTranslationEnabled")
    ] = None
    r"""Is translation enabled for the workflow"""

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