"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .builtinconnectors import BuiltInConnectors
from mistralai.gcp.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.gcp.client.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ToolUnionTypedDict = TypeAliasType("ToolUnionTypedDict", Union[BuiltInConnectors, str])


ToolUnion = TypeAliasType("ToolUnion", Union[BuiltInConnectors, str])


class ToolReferenceChunkTypedDict(TypedDict):
    tool: ToolUnionTypedDict
    title: str
    type: Literal["tool_reference"]
    url: NotRequired[Nullable[str]]
    favicon: NotRequired[Nullable[str]]
    description: NotRequired[Nullable[str]]


class ToolReferenceChunk(BaseModel):
    tool: ToolUnion

    title: str

    type: Annotated[
        Annotated[
            Optional[Literal["tool_reference"]],
            AfterValidator(validate_const("tool_reference")),
        ],
        pydantic.Field(alias="type"),
    ] = "tool_reference"

    url: OptionalNullable[str] = UNSET

    favicon: OptionalNullable[str] = UNSET

    description: OptionalNullable[str] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["type", "url", "favicon", "description"])
        nullable_fields = set(["url", "favicon", "description"])
        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


try:
    ToolReferenceChunk.model_rebuild()
except NameError:
    pass
