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

from __future__ import annotations
from .annotations import Annotations, AnnotationsTypedDict
from .mcpservericon import MCPServerIcon, MCPServerIconTypedDict
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, List, Literal
from typing_extensions import Annotated, NotRequired, TypedDict


class ResourceLinkTypedDict(TypedDict):
    r"""A resource that the server is capable of reading, included in a prompt or tool call result.

    Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
    """

    name: str
    uri: str
    title: NotRequired[Nullable[str]]
    description: NotRequired[Nullable[str]]
    mime_type: NotRequired[Nullable[str]]
    size: NotRequired[Nullable[int]]
    icons: NotRequired[Nullable[List[MCPServerIconTypedDict]]]
    annotations: NotRequired[Nullable[AnnotationsTypedDict]]
    meta: NotRequired[Nullable[Dict[str, Any]]]
    type: Literal["resource_link"]


class ResourceLink(BaseModel):
    r"""A resource that the server is capable of reading, included in a prompt or tool call result.

    Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
    """

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

    name: str

    uri: str

    title: OptionalNullable[str] = UNSET

    description: OptionalNullable[str] = UNSET

    mime_type: Annotated[OptionalNullable[str], pydantic.Field(alias="mimeType")] = (
        UNSET
    )

    size: OptionalNullable[int] = UNSET

    icons: OptionalNullable[List[MCPServerIcon]] = UNSET

    annotations: OptionalNullable[Annotations] = UNSET

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

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

    @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(
            [
                "title",
                "description",
                "mimeType",
                "size",
                "icons",
                "annotations",
                "_meta",
            ]
        )
        nullable_fields = set(
            [
                "title",
                "description",
                "mimeType",
                "size",
                "icons",
                "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:
    ResourceLink.model_rebuild()
except NameError:
    pass
