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

from __future__ import annotations
from .codeinterpretertool import CodeInterpreterTool, CodeInterpreterToolTypedDict
from .completionargs import CompletionArgs, CompletionArgsTypedDict
from .conversationinputs import ConversationInputs, ConversationInputsTypedDict
from .documentlibrarytool import DocumentLibraryTool, DocumentLibraryToolTypedDict
from .functiontool import FunctionTool, FunctionToolTypedDict
from .guardrailconfig import GuardrailConfig, GuardrailConfigTypedDict
from .imagegenerationtool import ImageGenerationTool, ImageGenerationToolTypedDict
from .websearchpremiumtool import WebSearchPremiumTool, WebSearchPremiumToolTypedDict
from .websearchtool import WebSearchTool, WebSearchToolTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import Field, model_serializer
from typing import Any, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ConversationStreamRequestHandoffExecution = Literal[
    "client",
    "server",
]


ConversationStreamRequestToolTypedDict = TypeAliasType(
    "ConversationStreamRequestToolTypedDict",
    Union[
        FunctionToolTypedDict,
        WebSearchToolTypedDict,
        WebSearchPremiumToolTypedDict,
        CodeInterpreterToolTypedDict,
        ImageGenerationToolTypedDict,
        DocumentLibraryToolTypedDict,
    ],
)


ConversationStreamRequestTool = Annotated[
    Union[
        CodeInterpreterTool,
        DocumentLibraryTool,
        FunctionTool,
        ImageGenerationTool,
        WebSearchTool,
        WebSearchPremiumTool,
    ],
    Field(discriminator="type"),
]


ConversationStreamRequestAgentVersionTypedDict = TypeAliasType(
    "ConversationStreamRequestAgentVersionTypedDict", Union[str, int]
)


ConversationStreamRequestAgentVersion = TypeAliasType(
    "ConversationStreamRequestAgentVersion", Union[str, int]
)


class ConversationStreamRequestTypedDict(TypedDict):
    inputs: ConversationInputsTypedDict
    stream: NotRequired[bool]
    store: NotRequired[Nullable[bool]]
    handoff_execution: NotRequired[Nullable[ConversationStreamRequestHandoffExecution]]
    instructions: NotRequired[Nullable[str]]
    tools: NotRequired[List[ConversationStreamRequestToolTypedDict]]
    r"""List of tools which are available to the model during the conversation."""
    completion_args: NotRequired[Nullable[CompletionArgsTypedDict]]
    guardrails: NotRequired[Nullable[List[GuardrailConfigTypedDict]]]
    name: NotRequired[Nullable[str]]
    description: NotRequired[Nullable[str]]
    metadata: NotRequired[Nullable[Dict[str, Any]]]
    agent_id: NotRequired[Nullable[str]]
    agent_version: NotRequired[Nullable[ConversationStreamRequestAgentVersionTypedDict]]
    model: NotRequired[Nullable[str]]


class ConversationStreamRequest(BaseModel):
    inputs: ConversationInputs

    stream: Optional[bool] = True

    store: OptionalNullable[bool] = UNSET

    handoff_execution: OptionalNullable[ConversationStreamRequestHandoffExecution] = (
        UNSET
    )

    instructions: OptionalNullable[str] = UNSET

    tools: Optional[List[ConversationStreamRequestTool]] = None
    r"""List of tools which are available to the model during the conversation."""

    completion_args: OptionalNullable[CompletionArgs] = UNSET

    guardrails: OptionalNullable[List[GuardrailConfig]] = UNSET

    name: OptionalNullable[str] = UNSET

    description: OptionalNullable[str] = UNSET

    metadata: OptionalNullable[Dict[str, Any]] = UNSET

    agent_id: OptionalNullable[str] = UNSET

    agent_version: OptionalNullable[ConversationStreamRequestAgentVersion] = UNSET

    model: OptionalNullable[str] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "stream",
                "store",
                "handoff_execution",
                "instructions",
                "tools",
                "completion_args",
                "guardrails",
                "name",
                "description",
                "metadata",
                "agent_id",
                "agent_version",
                "model",
            ]
        )
        nullable_fields = set(
            [
                "store",
                "handoff_execution",
                "instructions",
                "completion_args",
                "guardrails",
                "name",
                "description",
                "metadata",
                "agent_id",
                "agent_version",
                "model",
            ]
        )
        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
