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

from __future__ import annotations
from .mcpserverauthenticationrequirement import (
    MCPServerAuthenticationRequirement,
    MCPServerAuthenticationRequirementTypedDict,
)
from .mcpserverremoteheader import MCPServerRemoteHeader, MCPServerRemoteHeaderTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Union
from typing_extensions import Annotated, NotRequired, TypedDict


MCPServerRemoteType = Union[
    Literal[
        "streamable-http",
        "sse",
    ],
    UnrecognizedStr,
]
r"""Transport type"""


class MCPServerRemoteTypedDict(TypedDict):
    r"""Remote transport endpoint (SEP-2127)."""

    type: MCPServerRemoteType
    r"""Transport type"""
    url: str
    r"""Transport endpoint URL"""
    supported_protocol_versions: NotRequired[Nullable[List[str]]]
    headers: NotRequired[Nullable[List[MCPServerRemoteHeaderTypedDict]]]
    authentication: NotRequired[Nullable[MCPServerAuthenticationRequirementTypedDict]]


class MCPServerRemote(BaseModel):
    r"""Remote transport endpoint (SEP-2127)."""

    type: MCPServerRemoteType
    r"""Transport type"""

    url: str
    r"""Transport endpoint URL"""

    supported_protocol_versions: Annotated[
        OptionalNullable[List[str]], pydantic.Field(alias="supportedProtocolVersions")
    ] = UNSET

    headers: OptionalNullable[List[MCPServerRemoteHeader]] = UNSET

    authentication: OptionalNullable[MCPServerAuthenticationRequirement] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["supportedProtocolVersions", "headers", "authentication"]
        )
        nullable_fields = set(
            ["supportedProtocolVersions", "headers", "authentication"]
        )
        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:
    MCPServerRemote.model_rebuild()
except NameError:
    pass
