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

from __future__ import annotations
from enum import Enum
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class Severity(str, Enum):
    INFO = "info"
    WARNING = "warning"
    ERROR = "error"


class ValidationIssueTypedDict(TypedDict):
    r"""A single validation finding with severity, location, and description."""

    id: str
    r"""Stable machine-readable identifier (kebab-case)"""
    message: str
    r"""Human-readable description"""
    severity: NotRequired[Severity]
    path: NotRequired[Nullable[str]]
    r"""JSONPath-style location (e.g. $.context.task.steps[2])"""
    value: NotRequired[Nullable[str]]
    r"""The offending value, when it adds clarity"""


class ValidationIssue(BaseModel):
    r"""A single validation finding with severity, location, and description."""

    id: str
    r"""Stable machine-readable identifier (kebab-case)"""

    message: str
    r"""Human-readable description"""

    severity: Optional[Severity] = Severity.ERROR

    path: OptionalNullable[str] = UNSET
    r"""JSONPath-style location (e.g. $.context.task.steps[2])"""

    value: OptionalNullable[str] = UNSET
    r"""The offending value, when it adds clarity"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["severity", "path", "value"])
        nullable_fields = set(["path", "value"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m
