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

from __future__ import annotations
from .completionargs import CompletionArgs, CompletionArgsTypedDict
from .conversationinputs import ConversationInputs, ConversationInputsTypedDict
from .guardrailconfig import GuardrailConfig, GuardrailConfigTypedDict
from .metadatadict import MetadataDict, MetadataDictTypedDict
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 List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


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


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


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


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

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


class ConversationRestartStreamRequest(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[True]], AfterValidator(validate_const(True))],
        pydantic.Field(alias="stream"),
    ] = True

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

    handoff_execution: Optional[ConversationRestartStreamRequestHandoffExecution] = (
        "server"
    )

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

    guardrails: OptionalNullable[List[GuardrailConfig]] = UNSET

    metadata: OptionalNullable[MetadataDict] = UNSET
    r"""Custom metadata for the conversation."""

    agent_version: OptionalNullable[ConversationRestartStreamRequestAgentVersion] = (
        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:
    ConversationRestartStreamRequest.model_rebuild()
except NameError:
    pass
