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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.connection_test_result import ConnectionTestResult
from ..types.mcp_configuration_list_response import McpConfigurationListResponse
from ..types.mcp_configuration_response import McpConfigurationResponse
from .raw_client import AsyncRawMcpConfigurationsClient, RawMcpConfigurationsClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class McpConfigurationsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawMcpConfigurationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawMcpConfigurationsClient
        """
        return self._raw_client

    def list_mcp_configurations(
        self,
        *,
        organization_id: str,
        type: typing.Optional[str] = None,
        is_active: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpConfigurationListResponse:
        """
        List MCP configurations for an organization.

        Returns configurations accessible to the current user within the specified organization.

        Parameters
        ----------
        organization_id : str
            Organization ID

        type : typing.Optional[str]
            Filter by type: custom, streamline, personal_connector

        is_active : typing.Optional[bool]
            Filter by active status

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

        Returns
        -------
        McpConfigurationListResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.mcp_configurations.list_mcp_configurations(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.list_mcp_configurations(
            organization_id=organization_id, type=type, is_active=is_active, request_options=request_options
        )
        return _response.data

    def create_mcp_configuration(
        self,
        *,
        name: str,
        organization_id: str,
        server_url: str,
        transport_type: str,
        auth_type: str,
        credentials: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        tool_configuration: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpConfigurationResponse:
        """
        Create a new custom MCP configuration.

        Allows users to configure custom MCP servers with encrypted credentials.

        Parameters
        ----------
        name : str
            Display name

        organization_id : str
            Organization ID

        server_url : str
            HTTPS URL to MCP server

        transport_type : str
            Transport type: 'sse' or 'streamable_http'

        auth_type : str
            Authentication type: 'none', 'api_key', 'bearer_token', 'oauth'

        credentials : typing.Optional[typing.Dict[str, typing.Any]]
            Authentication credentials (will be encrypted)

        tool_configuration : typing.Optional[typing.Dict[str, typing.Any]]
            Tool enablement configuration

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

        Returns
        -------
        McpConfigurationResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.mcp_configurations.create_mcp_configuration(
            name="name",
            organization_id="organization_id",
            server_url="server_url",
            transport_type="transport_type",
            auth_type="auth_type",
        )
        """
        _response = self._raw_client.create_mcp_configuration(
            name=name,
            organization_id=organization_id,
            server_url=server_url,
            transport_type=transport_type,
            auth_type=auth_type,
            credentials=credentials,
            tool_configuration=tool_configuration,
            request_options=request_options,
        )
        return _response.data

    def get_mcp_configuration(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> McpConfigurationResponse:
        """
        Get a specific MCP configuration by ID.

        Returns the configuration if the user has access to it.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        McpConfigurationResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.mcp_configurations.get_mcp_configuration(
            config_id="config_id",
        )
        """
        _response = self._raw_client.get_mcp_configuration(config_id, request_options=request_options)
        return _response.data

    def update_mcp_configuration(
        self,
        config_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        server_url: typing.Optional[str] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        credentials: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        tool_configuration: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpConfigurationResponse:
        """
        Update an existing MCP configuration.

        Only the configuration owner can update it.

        Parameters
        ----------
        config_id : str

        name : typing.Optional[str]
            Display name

        server_url : typing.Optional[str]
            HTTPS URL to MCP server

        is_active : typing.Optional[bool]
            Enable/disable configuration

        credentials : typing.Optional[typing.Dict[str, typing.Any]]
            Updated credentials (will be encrypted)

        tool_configuration : typing.Optional[typing.Dict[str, typing.Any]]
            Tool enablement configuration

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

        Returns
        -------
        McpConfigurationResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.mcp_configurations.update_mcp_configuration(
            config_id="config_id",
        )
        """
        _response = self._raw_client.update_mcp_configuration(
            config_id,
            name=name,
            server_url=server_url,
            is_active=is_active,
            credentials=credentials,
            tool_configuration=tool_configuration,
            request_options=request_options,
        )
        return _response.data

    def delete_mcp_configuration(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete an MCP configuration (soft delete).

        Only the configuration owner can delete it.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.mcp_configurations.delete_mcp_configuration(
            config_id="config_id",
        )
        """
        _response = self._raw_client.delete_mcp_configuration(config_id, request_options=request_options)
        return _response.data

    def test_mcp_connection(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ConnectionTestResult:
        """
        Test connection to an MCP server.

        Verifies that the MCP server is reachable and returns available tools.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        ConnectionTestResult
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.mcp_configurations.test_mcp_connection(
            config_id="config_id",
        )
        """
        _response = self._raw_client.test_mcp_connection(config_id, request_options=request_options)
        return _response.data


class AsyncMcpConfigurationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawMcpConfigurationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawMcpConfigurationsClient
        """
        return self._raw_client

    async def list_mcp_configurations(
        self,
        *,
        organization_id: str,
        type: typing.Optional[str] = None,
        is_active: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpConfigurationListResponse:
        """
        List MCP configurations for an organization.

        Returns configurations accessible to the current user within the specified organization.

        Parameters
        ----------
        organization_id : str
            Organization ID

        type : typing.Optional[str]
            Filter by type: custom, streamline, personal_connector

        is_active : typing.Optional[bool]
            Filter by active status

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

        Returns
        -------
        McpConfigurationListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mcp_configurations.list_mcp_configurations(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_mcp_configurations(
            organization_id=organization_id, type=type, is_active=is_active, request_options=request_options
        )
        return _response.data

    async def create_mcp_configuration(
        self,
        *,
        name: str,
        organization_id: str,
        server_url: str,
        transport_type: str,
        auth_type: str,
        credentials: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        tool_configuration: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpConfigurationResponse:
        """
        Create a new custom MCP configuration.

        Allows users to configure custom MCP servers with encrypted credentials.

        Parameters
        ----------
        name : str
            Display name

        organization_id : str
            Organization ID

        server_url : str
            HTTPS URL to MCP server

        transport_type : str
            Transport type: 'sse' or 'streamable_http'

        auth_type : str
            Authentication type: 'none', 'api_key', 'bearer_token', 'oauth'

        credentials : typing.Optional[typing.Dict[str, typing.Any]]
            Authentication credentials (will be encrypted)

        tool_configuration : typing.Optional[typing.Dict[str, typing.Any]]
            Tool enablement configuration

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

        Returns
        -------
        McpConfigurationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mcp_configurations.create_mcp_configuration(
                name="name",
                organization_id="organization_id",
                server_url="server_url",
                transport_type="transport_type",
                auth_type="auth_type",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_mcp_configuration(
            name=name,
            organization_id=organization_id,
            server_url=server_url,
            transport_type=transport_type,
            auth_type=auth_type,
            credentials=credentials,
            tool_configuration=tool_configuration,
            request_options=request_options,
        )
        return _response.data

    async def get_mcp_configuration(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> McpConfigurationResponse:
        """
        Get a specific MCP configuration by ID.

        Returns the configuration if the user has access to it.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        McpConfigurationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mcp_configurations.get_mcp_configuration(
                config_id="config_id",
            )


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

    async def update_mcp_configuration(
        self,
        config_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        server_url: typing.Optional[str] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        credentials: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        tool_configuration: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> McpConfigurationResponse:
        """
        Update an existing MCP configuration.

        Only the configuration owner can update it.

        Parameters
        ----------
        config_id : str

        name : typing.Optional[str]
            Display name

        server_url : typing.Optional[str]
            HTTPS URL to MCP server

        is_active : typing.Optional[bool]
            Enable/disable configuration

        credentials : typing.Optional[typing.Dict[str, typing.Any]]
            Updated credentials (will be encrypted)

        tool_configuration : typing.Optional[typing.Dict[str, typing.Any]]
            Tool enablement configuration

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

        Returns
        -------
        McpConfigurationResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mcp_configurations.update_mcp_configuration(
                config_id="config_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_mcp_configuration(
            config_id,
            name=name,
            server_url=server_url,
            is_active=is_active,
            credentials=credentials,
            tool_configuration=tool_configuration,
            request_options=request_options,
        )
        return _response.data

    async def delete_mcp_configuration(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete an MCP configuration (soft delete).

        Only the configuration owner can delete it.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mcp_configurations.delete_mcp_configuration(
                config_id="config_id",
            )


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

    async def test_mcp_connection(
        self, config_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ConnectionTestResult:
        """
        Test connection to an MCP server.

        Verifies that the MCP server is reachable and returns available tools.

        Parameters
        ----------
        config_id : str

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

        Returns
        -------
        ConnectionTestResult
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.mcp_configurations.test_mcp_connection(
                config_id="config_id",
            )


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