"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 60a51ff1682b

from __future__ import annotations
from .agenthandoffentry import AgentHandoffEntry, AgentHandoffEntryTypedDict
from .functioncallentry import FunctionCallEntry, FunctionCallEntryTypedDict
from .functionresultentry import FunctionResultEntry, FunctionResultEntryTypedDict
from .messageinputentry import MessageInputEntry, MessageInputEntryTypedDict
from .messageoutputentry import MessageOutputEntry, MessageOutputEntryTypedDict
from .toolexecutionentry import ToolExecutionEntry, ToolExecutionEntryTypedDict
from mistralai.client.types import BaseModel, UNSET_SENTINEL
from mistralai.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, TypeAliasType, TypedDict


EntryTypedDict = TypeAliasType(
    "EntryTypedDict",
    Union[
        FunctionResultEntryTypedDict,
        MessageInputEntryTypedDict,
        MessageOutputEntryTypedDict,
        AgentHandoffEntryTypedDict,
        ToolExecutionEntryTypedDict,
        FunctionCallEntryTypedDict,
    ],
)


Entry = TypeAliasType(
    "Entry",
    Union[
        FunctionResultEntry,
        MessageInputEntry,
        MessageOutputEntry,
        AgentHandoffEntry,
        ToolExecutionEntry,
        FunctionCallEntry,
    ],
)


class ConversationHistoryTypedDict(TypedDict):
    r"""Retrieve all entries in a conversation."""

    conversation_id: str
    entries: List[EntryTypedDict]
    object: Literal["conversation.history"]


class ConversationHistory(BaseModel):
    r"""Retrieve all entries in a conversation."""

    conversation_id: str

    entries: List[Entry]

    object: Annotated[
        Annotated[
            Optional[Literal["conversation.history"]],
            AfterValidator(validate_const("conversation.history")),
        ],
        pydantic.Field(alias="object"),
    ] = "conversation.history"

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

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

        return m


try:
    ConversationHistory.model_rebuild()
except NameError:
    pass
