"""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 .guardrailconfig import GuardrailConfig, GuardrailConfigTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    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 Any, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, 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: Literal[False]
    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"""
    guardrails: NotRequired[Nullable[List[GuardrailConfigTypedDict]]]
    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: Annotated[
        Annotated[Optional[Literal[False]], AfterValidator(validate_const(False))],
        pydantic.Field(alias="stream"),
    ] = 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"""

    guardrails: OptionalNullable[List[GuardrailConfig]] = UNSET

    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",
                "guardrails",
                "metadata",
                "agent_version",
            ]
        )
        nullable_fields = set(["guardrails", "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, serialized.get(n))
            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


try:
    ConversationRestartRequest.model_rebuild()
except NameError:
    pass
