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

from __future__ import annotations
from .referencechunk import ReferenceChunk, ReferenceChunkTypedDict
from .textchunk import TextChunk, TextChunkTypedDict
from .toolreferencechunk import ToolReferenceChunk, ToolReferenceChunkTypedDict
from mistralai.azure.client.types import BaseModel, UNSET_SENTINEL
from mistralai.azure.client.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ThinkingTypedDict = TypeAliasType(
    "ThinkingTypedDict",
    Union[TextChunkTypedDict, ReferenceChunkTypedDict, ToolReferenceChunkTypedDict],
)


Thinking = TypeAliasType(
    "Thinking", Union[TextChunk, ReferenceChunk, ToolReferenceChunk]
)


class ThinkChunkTypedDict(TypedDict):
    thinking: List[ThinkingTypedDict]
    type: Literal["thinking"]
    closed: NotRequired[bool]
    r"""Whether the thinking chunk is closed or not. Currently only used for prefixing."""


class ThinkChunk(BaseModel):
    thinking: List[Thinking]

    type: Annotated[
        Annotated[Literal["thinking"], AfterValidator(validate_const("thinking"))],
        pydantic.Field(alias="type"),
    ] = "thinking"

    closed: Optional[bool] = None
    r"""Whether the thinking chunk is closed or not. Currently only used for prefixing."""

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

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

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

        return m


try:
    ThinkChunk.model_rebuild()
except NameError:
    pass
