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

from __future__ import annotations
from .completionargs import CompletionArgs, CompletionArgsTypedDict
from .conversationinputs import ConversationInputs, ConversationInputsTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any, Dict, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


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


ConversationRestartRequestAgentVersionTypedDict = TypeAliasType(
    "ConversationRestartRequestAgentVersionTypedDict", Union[str, int]
)
r"""Specific version of the agent to use when restarting. If not provided, uses the current version."""


ConversationRestartRequestAgentVersion = TypeAliasType(
    "ConversationRestartRequestAgentVersion", Union[str, int]
)
r"""Specific version of the agent to use when restarting. If not provided, uses the current version."""


class ConversationRestartRequestTypedDict(TypedDict):
    r"""Request to restart a new conversation from a given entry in the conversation."""

    from_entry_id: str
    inputs: NotRequired[ConversationInputsTypedDict]
    stream: NotRequired[bool]
    store: NotRequired[bool]
    r"""Whether to store the results into our servers or not."""
    handoff_execution: NotRequired[ConversationRestartRequestHandoffExecution]
    completion_args: NotRequired[CompletionArgsTypedDict]
    r"""White-listed arguments from the completion API"""
    metadata: NotRequired[Nullable[Dict[str, Any]]]
    r"""Custom metadata for the conversation."""
    agent_version: NotRequired[
        Nullable[ConversationRestartRequestAgentVersionTypedDict]
    ]
    r"""Specific version of the agent to use when restarting. If not provided, uses the current version."""


class ConversationRestartRequest(BaseModel):
    r"""Request to restart a new conversation from a given entry in the conversation."""

    from_entry_id: str

    inputs: Optional[ConversationInputs] = None

    stream: Optional[bool] = False

    store: Optional[bool] = True
    r"""Whether to store the results into our servers or not."""

    handoff_execution: Optional[ConversationRestartRequestHandoffExecution] = "server"

    completion_args: Optional[CompletionArgs] = None
    r"""White-listed arguments from the completion API"""

    metadata: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Custom metadata for the conversation."""

    agent_version: OptionalNullable[ConversationRestartRequestAgentVersion] = UNSET
    r"""Specific version of the agent to use when restarting. If not provided, uses the current version."""

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