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

from __future__ import annotations
from .executiondetailssourceenum import ExecutionDetailsSourceEnum
from .executiondetailsstatusenum import ExecutionDetailsStatusEnum
from .providersidenum import ProvidersIDEnum
from novu_py.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ActivityNotificationExecutionDetailResponseDtoTypedDict(TypedDict):
    id: str
    r"""Unique identifier of the execution detail"""
    status: ExecutionDetailsStatusEnum
    r"""Status of the execution detail"""
    detail: str
    r"""Detailed information about the execution"""
    is_retry: bool
    r"""Whether the execution is a retry or not"""
    is_test: bool
    r"""Whether the execution is a test or not"""
    source: ExecutionDetailsSourceEnum
    r"""Source of the execution detail"""
    created_at: NotRequired[str]
    r"""Creation time of the execution detail"""
    provider_id: NotRequired[ProvidersIDEnum]
    r"""Provider ID of the job"""
    raw: NotRequired[Nullable[str]]
    r"""Raw data of the execution"""


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

    status: ExecutionDetailsStatusEnum
    r"""Status of the execution detail"""

    detail: str
    r"""Detailed information about the execution"""

    is_retry: Annotated[bool, pydantic.Field(alias="isRetry")]
    r"""Whether the execution is a retry or not"""

    is_test: Annotated[bool, pydantic.Field(alias="isTest")]
    r"""Whether the execution is a test or not"""

    source: ExecutionDetailsSourceEnum
    r"""Source of the execution detail"""

    created_at: Annotated[Optional[str], pydantic.Field(alias="createdAt")] = None
    r"""Creation time of the execution detail"""

    provider_id: Annotated[
        Optional[ProvidersIDEnum], pydantic.Field(alias="providerId")
    ] = None
    r"""Provider ID of the job"""

    raw: OptionalNullable[str] = UNSET
    r"""Raw data of the execution"""

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