# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import typing

from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.conv_ai_secret_locator import ConvAiSecretLocator
from ...types.mcp_approval_policy import McpApprovalPolicy
from ...types.mcp_server_config_input import McpServerConfigInput
from ...types.mcp_server_response_model import McpServerResponseModel
from ...types.mcp_servers_response_model import McpServersResponseModel
from ...types.pre_tool_speech_mode import PreToolSpeechMode
from ...types.tool_call_sound_behavior import ToolCallSoundBehavior
from ...types.tool_call_sound_type import ToolCallSoundType
from ...types.tool_execution_mode import ToolExecutionMode
from ...types.tool_interruption_mode import ToolInterruptionMode
from .raw_client import AsyncRawMcpServersClient, RawMcpServersClient
from .types.mcp_server_config_update_request_model_auth_connection import (
    McpServerConfigUpdateRequestModelAuthConnection,
)
from .types.mcp_server_config_update_request_model_request_headers_value import (
    McpServerConfigUpdateRequestModelRequestHeadersValue,
)

if typing.TYPE_CHECKING:
    from .approval_policy.client import ApprovalPolicyClient, AsyncApprovalPolicyClient
    from .tool_approvals.client import AsyncToolApprovalsClient, ToolApprovalsClient
    from .tool_configs.client import AsyncToolConfigsClient, ToolConfigsClient
    from .tools.client import AsyncToolsClient, ToolsClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class McpServersClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMcpServersClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._tools: typing.Optional[ToolsClient] = None
        self._approval_policy: typing.Optional[ApprovalPolicyClient] = None
        self._tool_approvals: typing.Optional[ToolApprovalsClient] = None
        self._tool_configs: typing.Optional[ToolConfigsClient] = None

    @property
    def with_raw_response(self) -> RawMcpServersClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawMcpServersClient
        """
        return self._raw_client

    def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> McpServersResponseModel:
        """
        Retrieve all MCP server configurations available in the workspace.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServersResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.mcp_servers.list()
        """
        _response = self._raw_client.list(request_options=request_options)
        return _response.data

    def create(
        self, *, config: McpServerConfigInput, request_options: typing.Optional[RequestOptions] = None
    ) -> McpServerResponseModel:
        """
        Create a new MCP server configuration in the workspace.

        Parameters
        ----------
        config : McpServerConfigInput
            Configuration details for the MCP Server.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServerResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs, McpServerConfigInput

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.mcp_servers.create(
            config=McpServerConfigInput(
                url="url",
                name="name",
            ),
        )
        """
        _response = self._raw_client.create(config=config, request_options=request_options)
        return _response.data

    def get(
        self, mcp_server_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> McpServerResponseModel:
        """
        Retrieve a specific MCP server configuration from the workspace.

        Parameters
        ----------
        mcp_server_id : str
            ID of the MCP Server.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServerResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.mcp_servers.get(
            mcp_server_id="mcp_server_id",
        )
        """
        _response = self._raw_client.get(mcp_server_id, request_options=request_options)
        return _response.data

    def delete(self, mcp_server_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> typing.Any:
        """
        Delete a specific MCP server configuration from the workspace.

        Parameters
        ----------
        mcp_server_id : str
            ID of the MCP Server.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.mcp_servers.delete(
            mcp_server_id="mcp_server_id",
        )
        """
        _response = self._raw_client.delete(mcp_server_id, request_options=request_options)
        return _response.data

    def update(
        self,
        mcp_server_id: str,
        *,
        approval_policy: typing.Optional[McpApprovalPolicy] = OMIT,
        force_pre_tool_speech: typing.Optional[bool] = OMIT,
        pre_tool_speech: typing.Optional[PreToolSpeechMode] = OMIT,
        disable_interruptions: typing.Optional[bool] = OMIT,
        interruption_mode: typing.Optional[ToolInterruptionMode] = OMIT,
        tool_call_sound: typing.Optional[ToolCallSoundType] = OMIT,
        tool_call_sound_behavior: typing.Optional[ToolCallSoundBehavior] = OMIT,
        execution_mode: typing.Optional[ToolExecutionMode] = OMIT,
        response_timeout_secs: typing.Optional[int] = OMIT,
        request_headers: typing.Optional[
            typing.Dict[str, typing.Optional[McpServerConfigUpdateRequestModelRequestHeadersValue]]
        ] = OMIT,
        disable_compression: typing.Optional[bool] = OMIT,
        secret_token: typing.Optional[ConvAiSecretLocator] = OMIT,
        auth_connection: typing.Optional[McpServerConfigUpdateRequestModelAuthConnection] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpServerResponseModel:
        """
        Update the configuration settings for an MCP server.

        Parameters
        ----------
        mcp_server_id : str
            ID of the MCP Server.

        approval_policy : typing.Optional[McpApprovalPolicy]
            The approval mode to set for the MCP server

        force_pre_tool_speech : typing.Optional[bool]
            DEPRECATED: use `pre_tool_speech` instead. If set, overrides the server's force_pre_tool_speech setting for this tool.

        pre_tool_speech : typing.Optional[PreToolSpeechMode]
            If set, overrides the server's pre_tool_speech setting for this tool.

        disable_interruptions : typing.Optional[bool]
            DEPRECATED: use `interruption_mode` instead. If set, overrides the server's disable_interruptions setting for this tool.

        interruption_mode : typing.Optional[ToolInterruptionMode]
            If set, overrides the server's interruption_mode setting for this tool.

        tool_call_sound : typing.Optional[ToolCallSoundType]
            Predefined tool call sound type to play during tool execution for all tools from this MCP server

        tool_call_sound_behavior : typing.Optional[ToolCallSoundBehavior]
            Determines when the tool call sound should play for all tools from this MCP server

        execution_mode : typing.Optional[ToolExecutionMode]
            If set, overrides the server's execution_mode setting for this tool

        response_timeout_secs : typing.Optional[int]
            The maximum time in seconds to wait for each MCP tool call to complete.

        request_headers : typing.Optional[typing.Dict[str, typing.Optional[McpServerConfigUpdateRequestModelRequestHeadersValue]]]
            The headers to include in requests to the MCP server

        disable_compression : typing.Optional[bool]
            Whether to disable HTTP compression for this MCP server

        secret_token : typing.Optional[ConvAiSecretLocator]
            Optional secret token for authentication with this MCP server

        auth_connection : typing.Optional[McpServerConfigUpdateRequestModelAuthConnection]
            Optional auth connection to use for authentication with this MCP server

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServerResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.mcp_servers.update(
            mcp_server_id="mcp_server_id",
        )
        """
        _response = self._raw_client.update(
            mcp_server_id,
            approval_policy=approval_policy,
            force_pre_tool_speech=force_pre_tool_speech,
            pre_tool_speech=pre_tool_speech,
            disable_interruptions=disable_interruptions,
            interruption_mode=interruption_mode,
            tool_call_sound=tool_call_sound,
            tool_call_sound_behavior=tool_call_sound_behavior,
            execution_mode=execution_mode,
            response_timeout_secs=response_timeout_secs,
            request_headers=request_headers,
            disable_compression=disable_compression,
            secret_token=secret_token,
            auth_connection=auth_connection,
            request_options=request_options,
        )
        return _response.data

    @property
    def tools(self):
        if self._tools is None:
            from .tools.client import ToolsClient  # noqa: E402

            self._tools = ToolsClient(client_wrapper=self._client_wrapper)
        return self._tools

    @property
    def approval_policy(self):
        if self._approval_policy is None:
            from .approval_policy.client import ApprovalPolicyClient  # noqa: E402

            self._approval_policy = ApprovalPolicyClient(client_wrapper=self._client_wrapper)
        return self._approval_policy

    @property
    def tool_approvals(self):
        if self._tool_approvals is None:
            from .tool_approvals.client import ToolApprovalsClient  # noqa: E402

            self._tool_approvals = ToolApprovalsClient(client_wrapper=self._client_wrapper)
        return self._tool_approvals

    @property
    def tool_configs(self):
        if self._tool_configs is None:
            from .tool_configs.client import ToolConfigsClient  # noqa: E402

            self._tool_configs = ToolConfigsClient(client_wrapper=self._client_wrapper)
        return self._tool_configs


class AsyncMcpServersClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMcpServersClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._tools: typing.Optional[AsyncToolsClient] = None
        self._approval_policy: typing.Optional[AsyncApprovalPolicyClient] = None
        self._tool_approvals: typing.Optional[AsyncToolApprovalsClient] = None
        self._tool_configs: typing.Optional[AsyncToolConfigsClient] = None

    @property
    def with_raw_response(self) -> AsyncRawMcpServersClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawMcpServersClient
        """
        return self._raw_client

    async def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> McpServersResponseModel:
        """
        Retrieve all MCP server configurations available in the workspace.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServersResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.mcp_servers.list()


        asyncio.run(main())
        """
        _response = await self._raw_client.list(request_options=request_options)
        return _response.data

    async def create(
        self, *, config: McpServerConfigInput, request_options: typing.Optional[RequestOptions] = None
    ) -> McpServerResponseModel:
        """
        Create a new MCP server configuration in the workspace.

        Parameters
        ----------
        config : McpServerConfigInput
            Configuration details for the MCP Server.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServerResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs, McpServerConfigInput

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.mcp_servers.create(
                config=McpServerConfigInput(
                    url="url",
                    name="name",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(config=config, request_options=request_options)
        return _response.data

    async def get(
        self, mcp_server_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> McpServerResponseModel:
        """
        Retrieve a specific MCP server configuration from the workspace.

        Parameters
        ----------
        mcp_server_id : str
            ID of the MCP Server.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServerResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.mcp_servers.get(
                mcp_server_id="mcp_server_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(mcp_server_id, request_options=request_options)
        return _response.data

    async def delete(
        self, mcp_server_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Any:
        """
        Delete a specific MCP server configuration from the workspace.

        Parameters
        ----------
        mcp_server_id : str
            ID of the MCP Server.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Any
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.mcp_servers.delete(
                mcp_server_id="mcp_server_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(mcp_server_id, request_options=request_options)
        return _response.data

    async def update(
        self,
        mcp_server_id: str,
        *,
        approval_policy: typing.Optional[McpApprovalPolicy] = OMIT,
        force_pre_tool_speech: typing.Optional[bool] = OMIT,
        pre_tool_speech: typing.Optional[PreToolSpeechMode] = OMIT,
        disable_interruptions: typing.Optional[bool] = OMIT,
        interruption_mode: typing.Optional[ToolInterruptionMode] = OMIT,
        tool_call_sound: typing.Optional[ToolCallSoundType] = OMIT,
        tool_call_sound_behavior: typing.Optional[ToolCallSoundBehavior] = OMIT,
        execution_mode: typing.Optional[ToolExecutionMode] = OMIT,
        response_timeout_secs: typing.Optional[int] = OMIT,
        request_headers: typing.Optional[
            typing.Dict[str, typing.Optional[McpServerConfigUpdateRequestModelRequestHeadersValue]]
        ] = OMIT,
        disable_compression: typing.Optional[bool] = OMIT,
        secret_token: typing.Optional[ConvAiSecretLocator] = OMIT,
        auth_connection: typing.Optional[McpServerConfigUpdateRequestModelAuthConnection] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpServerResponseModel:
        """
        Update the configuration settings for an MCP server.

        Parameters
        ----------
        mcp_server_id : str
            ID of the MCP Server.

        approval_policy : typing.Optional[McpApprovalPolicy]
            The approval mode to set for the MCP server

        force_pre_tool_speech : typing.Optional[bool]
            DEPRECATED: use `pre_tool_speech` instead. If set, overrides the server's force_pre_tool_speech setting for this tool.

        pre_tool_speech : typing.Optional[PreToolSpeechMode]
            If set, overrides the server's pre_tool_speech setting for this tool.

        disable_interruptions : typing.Optional[bool]
            DEPRECATED: use `interruption_mode` instead. If set, overrides the server's disable_interruptions setting for this tool.

        interruption_mode : typing.Optional[ToolInterruptionMode]
            If set, overrides the server's interruption_mode setting for this tool.

        tool_call_sound : typing.Optional[ToolCallSoundType]
            Predefined tool call sound type to play during tool execution for all tools from this MCP server

        tool_call_sound_behavior : typing.Optional[ToolCallSoundBehavior]
            Determines when the tool call sound should play for all tools from this MCP server

        execution_mode : typing.Optional[ToolExecutionMode]
            If set, overrides the server's execution_mode setting for this tool

        response_timeout_secs : typing.Optional[int]
            The maximum time in seconds to wait for each MCP tool call to complete.

        request_headers : typing.Optional[typing.Dict[str, typing.Optional[McpServerConfigUpdateRequestModelRequestHeadersValue]]]
            The headers to include in requests to the MCP server

        disable_compression : typing.Optional[bool]
            Whether to disable HTTP compression for this MCP server

        secret_token : typing.Optional[ConvAiSecretLocator]
            Optional secret token for authentication with this MCP server

        auth_connection : typing.Optional[McpServerConfigUpdateRequestModelAuthConnection]
            Optional auth connection to use for authentication with this MCP server

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        McpServerResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.mcp_servers.update(
                mcp_server_id="mcp_server_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            mcp_server_id,
            approval_policy=approval_policy,
            force_pre_tool_speech=force_pre_tool_speech,
            pre_tool_speech=pre_tool_speech,
            disable_interruptions=disable_interruptions,
            interruption_mode=interruption_mode,
            tool_call_sound=tool_call_sound,
            tool_call_sound_behavior=tool_call_sound_behavior,
            execution_mode=execution_mode,
            response_timeout_secs=response_timeout_secs,
            request_headers=request_headers,
            disable_compression=disable_compression,
            secret_token=secret_token,
            auth_connection=auth_connection,
            request_options=request_options,
        )
        return _response.data

    @property
    def tools(self):
        if self._tools is None:
            from .tools.client import AsyncToolsClient  # noqa: E402

            self._tools = AsyncToolsClient(client_wrapper=self._client_wrapper)
        return self._tools

    @property
    def approval_policy(self):
        if self._approval_policy is None:
            from .approval_policy.client import AsyncApprovalPolicyClient  # noqa: E402

            self._approval_policy = AsyncApprovalPolicyClient(client_wrapper=self._client_wrapper)
        return self._approval_policy

    @property
    def tool_approvals(self):
        if self._tool_approvals is None:
            from .tool_approvals.client import AsyncToolApprovalsClient  # noqa: E402

            self._tool_approvals = AsyncToolApprovalsClient(client_wrapper=self._client_wrapper)
        return self._tool_approvals

    @property
    def tool_configs(self):
        if self._tool_configs is None:
            from .tool_configs.client import AsyncToolConfigsClient  # noqa: E402

            self._tool_configs = AsyncToolConfigsClient(client_wrapper=self._client_wrapper)
        return self._tool_configs
