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

from __future__ import annotations
from .annotations import Annotations, AnnotationsTypedDict
from .blobresourcecontents import BlobResourceContents, BlobResourceContentsTypedDict
from .textresourcecontents import TextResourceContents, TextResourceContentsTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import validate_const
import pydantic
from pydantic import ConfigDict, model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Any, Dict, Literal, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ResourceTypedDict = TypeAliasType(
    "ResourceTypedDict",
    Union[TextResourceContentsTypedDict, BlobResourceContentsTypedDict],
)


Resource = TypeAliasType("Resource", Union[TextResourceContents, BlobResourceContents])


class EmbeddedResourceTypedDict(TypedDict):
    r"""The contents of a resource, embedded into a prompt or tool call result.

    It is up to the client how best to render embedded resources for the benefit
    of the LLM and/or the user.
    """

    resource: ResourceTypedDict
    type: Literal["resource"]
    annotations: NotRequired[Nullable[AnnotationsTypedDict]]
    meta: NotRequired[Nullable[Dict[str, Any]]]


class EmbeddedResource(BaseModel):
    r"""The contents of a resource, embedded into a prompt or tool call result.

    It is up to the client how best to render embedded resources for the benefit
    of the LLM and/or the user.
    """

    model_config = ConfigDict(
        populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
    )
    __pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)

    resource: Resource

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

    annotations: OptionalNullable[Annotations] = UNSET

    meta: Annotated[OptionalNullable[Dict[str, Any]], pydantic.Field(alias="_meta")] = (
        UNSET
    )

    @property
    def additional_properties(self):
        return self.__pydantic_extra__

    @additional_properties.setter
    def additional_properties(self, value):
        self.__pydantic_extra__ = value  # pyright: ignore[reportIncompatibleVariableOverride]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["annotations", "_meta"])
        nullable_fields = set(["annotations", "_meta"])
        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))
            serialized.pop(k, serialized.pop(n, None))
            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
        for k, v in serialized.items():
            m[k] = v

        return m


try:
    EmbeddedResource.model_rebuild()
except NameError:
    pass
