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

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


class InputParameterType(str, Enum):
    STRING = "string"
    NUMBER = "number"
    INTEGER = "integer"
    BOOLEAN = "boolean"
    OBJECT = "object"
    ARRAY = "array"
    NULL = "null"


class InputParameterTypedDict(TypedDict):
    name: str
    r"""The name of the property."""
    type: NotRequired[Nullable[InputParameterType]]
    description: NotRequired[Nullable[str]]
    title: NotRequired[Nullable[str]]
    format_: NotRequired[Nullable[str]]
    pattern: NotRequired[Nullable[str]]
    enum: NotRequired[Nullable[List[str]]]
    examples: NotRequired[Nullable[List[Any]]]
    required: NotRequired[bool]


class InputParameter(BaseModel):
    name: str
    r"""The name of the property."""

    type: OptionalNullable[InputParameterType] = UNSET

    description: OptionalNullable[str] = UNSET

    title: OptionalNullable[str] = UNSET

    format_: Annotated[OptionalNullable[str], pydantic.Field(alias="format")] = UNSET

    pattern: OptionalNullable[str] = UNSET

    enum: OptionalNullable[List[str]] = UNSET

    examples: OptionalNullable[List[Any]] = UNSET

    required: Optional[bool] = True

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "type",
                "description",
                "title",
                "format",
                "pattern",
                "enum",
                "examples",
                "required",
            ]
        )
        nullable_fields = set(
            ["type", "description", "title", "format", "pattern", "enum", "examples"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
