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

from __future__ import annotations
from novu_py import utils
from novu_py.types import BaseModel, Nullable, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Optional, Union
from typing_extensions import Annotated, TypeAliasType, TypedDict


ValidationErrorDtoValueTypedDict = TypeAliasType(
    "ValidationErrorDtoValueTypedDict",
    Union[str, float, bool, Dict[str, Any], List[Dict[str, Any]]],
)


ValidationErrorDtoValue = TypeAliasType(
    "ValidationErrorDtoValue",
    Union[str, float, bool, Dict[str, Any], List[Dict[str, Any]]],
)


class ErrorsTypedDict(TypedDict):
    messages: List[str]
    value: Nullable[ValidationErrorDtoValueTypedDict]


class Errors(BaseModel):
    messages: List[str]

    value: Nullable[ValidationErrorDtoValue]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = ["value"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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 ValidationErrorDtoData(BaseModel):
    status_code: Annotated[float, pydantic.Field(alias="statusCode")]
    r"""HTTP status code of the error response."""

    timestamp: str
    r"""Timestamp of when the error occurred."""

    path: str
    r"""The path where the error occurred."""

    message: str
    r"""A detailed error message."""

    errors: Dict[str, Errors]
    r"""A record of validation errors keyed by field name"""

    ctx: Optional[Dict[str, Any]] = None
    r"""Optional context object for additional error details."""

    error_id: Annotated[Optional[str], pydantic.Field(alias="errorId")] = None
    r"""Optional unique identifier for the error, useful for tracking using Sentry and
    New Relic, only available for 500.
    """


class ValidationErrorDto(Exception):
    data: ValidationErrorDtoData

    def __init__(self, data: ValidationErrorDtoData):
        self.data = data

    def __str__(self) -> str:
        return utils.marshal_json(self.data, ValidationErrorDtoData)
