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

from __future__ import annotations
from .codeinterpretertool import CodeInterpreterTool, CodeInterpreterToolTypedDict
from .completionargs import CompletionArgs, CompletionArgsTypedDict
from .customconnector import CustomConnector, CustomConnectorTypedDict
from .documentlibrarytool import DocumentLibraryTool, DocumentLibraryToolTypedDict
from .functiontool import FunctionTool, FunctionToolTypedDict
from .guardrailconfig import GuardrailConfig, GuardrailConfigTypedDict
from .imagegenerationtool import ImageGenerationTool, ImageGenerationToolTypedDict
from .metadatadict import MetadataDict, MetadataDictTypedDict
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 List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


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


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


class UpdateAgentRequestTypedDict(TypedDict):
    instructions: NotRequired[Nullable[str]]
    r"""Instruction prompt the model will follow during the conversation."""
    tools: NotRequired[List[UpdateAgentRequestToolTypedDict]]
    r"""List of tools which are available to the model during the conversation."""
    completion_args: NotRequired[CompletionArgsTypedDict]
    r"""White-listed arguments from the completion API"""
    guardrails: NotRequired[Nullable[List[GuardrailConfigTypedDict]]]
    model: NotRequired[Nullable[str]]
    name: NotRequired[Nullable[str]]
    description: NotRequired[Nullable[str]]
    handoffs: NotRequired[Nullable[List[str]]]
    deployment_chat: NotRequired[Nullable[bool]]
    metadata: NotRequired[Nullable[MetadataDictTypedDict]]
    version_message: NotRequired[Nullable[str]]


class UpdateAgentRequest(BaseModel):
    instructions: OptionalNullable[str] = UNSET
    r"""Instruction prompt the model will follow during the conversation."""

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

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

    guardrails: OptionalNullable[List[GuardrailConfig]] = UNSET

    model: OptionalNullable[str] = UNSET

    name: OptionalNullable[str] = UNSET

    description: OptionalNullable[str] = UNSET

    handoffs: OptionalNullable[List[str]] = UNSET

    deployment_chat: OptionalNullable[bool] = UNSET

    metadata: OptionalNullable[MetadataDict] = UNSET

    version_message: OptionalNullable[str] = UNSET

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