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

from __future__ import annotations
from openrouter.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from openrouter.utils import validate_open_enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Any, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


OpenResponsesMcpToolType = Literal["mcp",]


class AllowedToolsTypedDict(TypedDict):
    tool_names: NotRequired[List[str]]
    read_only: NotRequired[bool]


class AllowedTools(BaseModel):
    tool_names: Optional[List[str]] = None

    read_only: Optional[bool] = None


ConnectorID = Union[
    Literal[
        "connector_dropbox",
        "connector_gmail",
        "connector_googlecalendar",
        "connector_googledrive",
        "connector_microsoftteams",
        "connector_outlookcalendar",
        "connector_outlookemail",
        "connector_sharepoint",
    ],
    UnrecognizedStr,
]


RequireApprovalNever = Literal["never",]


RequireApprovalAlways = Literal["always",]


class NeverTypedDict(TypedDict):
    tool_names: NotRequired[List[str]]


class Never(BaseModel):
    tool_names: Optional[List[str]] = None


class AlwaysTypedDict(TypedDict):
    tool_names: NotRequired[List[str]]


class Always(BaseModel):
    tool_names: Optional[List[str]] = None


class RequireApprovalTypedDict(TypedDict):
    never: NotRequired[NeverTypedDict]
    always: NotRequired[AlwaysTypedDict]


class RequireApproval(BaseModel):
    never: Optional[Never] = None

    always: Optional[Always] = None


class OpenResponsesMcpToolTypedDict(TypedDict):
    r"""MCP (Model Context Protocol) tool configuration"""

    type: OpenResponsesMcpToolType
    server_label: str
    allowed_tools: NotRequired[Nullable[Any]]
    authorization: NotRequired[str]
    connector_id: NotRequired[ConnectorID]
    headers: NotRequired[Nullable[Dict[str, str]]]
    require_approval: NotRequired[Nullable[Any]]
    server_description: NotRequired[str]
    server_url: NotRequired[str]


class OpenResponsesMcpTool(BaseModel):
    r"""MCP (Model Context Protocol) tool configuration"""

    type: OpenResponsesMcpToolType

    server_label: str

    allowed_tools: OptionalNullable[Any] = UNSET

    authorization: Optional[str] = None

    connector_id: Annotated[
        Optional[ConnectorID], PlainValidator(validate_open_enum(False))
    ] = None

    headers: OptionalNullable[Dict[str, str]] = UNSET

    require_approval: OptionalNullable[Any] = UNSET

    server_description: Optional[str] = None

    server_url: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "allowed_tools",
            "authorization",
            "connector_id",
            "headers",
            "require_approval",
            "server_description",
            "server_url",
        ]
        nullable_fields = ["allowed_tools", "headers", "require_approval"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
