# 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.get_tool_dependent_agents_response_model import GetToolDependentAgentsResponseModel
from ...types.sort_direction import SortDirection
from ...types.tool_request_model import ToolRequestModel
from ...types.tool_response_model import ToolResponseModel
from ...types.tool_sort_by import ToolSortBy
from ...types.tool_type_filter import ToolTypeFilter
from ...types.tools_response_model import ToolsResponseModel
from .raw_client import AsyncRawToolsClient, RawToolsClient

if typing.TYPE_CHECKING:
    from .executions.client import AsyncExecutionsClient, ExecutionsClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ToolsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawToolsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._executions: typing.Optional[ExecutionsClient] = None

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

        Returns
        -------
        RawToolsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        search: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        show_only_owned_documents: typing.Optional[bool] = None,
        created_by_user_id: typing.Optional[str] = None,
        types: typing.Optional[typing.Union[ToolTypeFilter, typing.Sequence[ToolTypeFilter]]] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        sort_by: typing.Optional[ToolSortBy] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolsResponseModel:
        """
        Get all available tools in the workspace.

        Parameters
        ----------
        search : typing.Optional[str]
            If specified, the endpoint returns only tools whose names start with this string.

        page_size : typing.Optional[int]
            How many documents to return at maximum. Can not exceed 100, defaults to 30.

        show_only_owned_documents : typing.Optional[bool]
            If set to true, the endpoint will return only tools owned by you (and not shared from somebody else). Deprecated: use created_by_user_id instead.

        created_by_user_id : typing.Optional[str]
            Filter tools by creator user ID. When set, only tools created by this user are returned. Takes precedence over show_only_owned_documents. Use '@me' to refer to the authenticated user.

        types : typing.Optional[typing.Union[ToolTypeFilter, typing.Sequence[ToolTypeFilter]]]
            If present, the endpoint will return only tools of the given types.

        sort_direction : typing.Optional[SortDirection]
            The direction to sort the results

        sort_by : typing.Optional[ToolSortBy]
            The field to sort the results by

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

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

        Returns
        -------
        ToolsResponseModel
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tools.list(
            search="search",
            page_size=1,
            show_only_owned_documents=True,
            created_by_user_id="created_by_user_id",
            types=["webhook"],
            sort_direction="asc",
            sort_by="name",
            cursor="cursor",
        )
        """
        _response = self._raw_client.list(
            search=search,
            page_size=page_size,
            show_only_owned_documents=show_only_owned_documents,
            created_by_user_id=created_by_user_id,
            types=types,
            sort_direction=sort_direction,
            sort_by=sort_by,
            cursor=cursor,
            request_options=request_options,
        )
        return _response.data

    def create(
        self, *, request: ToolRequestModel, request_options: typing.Optional[RequestOptions] = None
    ) -> ToolResponseModel:
        """
        Add a new tool to the available tools in the workspace.

        Parameters
        ----------
        request : ToolRequestModel

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

        Returns
        -------
        ToolResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import (
            ElevenLabs,
            ToolRequestModel,
            ToolRequestModelToolConfig_Client,
        )

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tools.create(
            request=ToolRequestModel(
                tool_config=ToolRequestModelToolConfig_Client(
                    name="name",
                    description="description",
                    expects_response=False,
                ),
            ),
        )
        """
        _response = self._raw_client.create(request=request, request_options=request_options)
        return _response.data

    def get(
        self,
        tool_id: str,
        *,
        environment: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolResponseModel:
        """
        Get tool that is available in the workspace.

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        environment : typing.Optional[str]
            Environment whose values are used when the MCP server URL, headers, or auth connection reference environment variables. Mirrors the environment a conversation would run in; defaults to production.

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

        Returns
        -------
        ToolResponseModel
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tools.get(
            tool_id="tool_id",
            environment="environment",
        )
        """
        _response = self._raw_client.get(tool_id, environment=environment, request_options=request_options)
        return _response.data

    def delete(
        self,
        tool_id: str,
        *,
        force: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Delete tool from the workspace.

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        force : typing.Optional[bool]
            If set to true, the tool will be deleted regardless of whether it is used by any agents and it will be removed from the dependent agents and branches.

        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.tools.delete(
            tool_id="tool_id",
            force=True,
        )
        """
        _response = self._raw_client.delete(tool_id, force=force, request_options=request_options)
        return _response.data

    def update(
        self, tool_id: str, *, request: ToolRequestModel, request_options: typing.Optional[RequestOptions] = None
    ) -> ToolResponseModel:
        """
        Update tool that is available in the workspace.

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        request : ToolRequestModel

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

        Returns
        -------
        ToolResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import (
            ElevenLabs,
            ToolRequestModel,
            ToolRequestModelToolConfig_Client,
        )

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tools.update(
            tool_id="tool_id",
            request=ToolRequestModel(
                tool_config=ToolRequestModelToolConfig_Client(
                    name="name",
                    description="description",
                    expects_response=False,
                ),
            ),
        )
        """
        _response = self._raw_client.update(tool_id, request=request, request_options=request_options)
        return _response.data

    def get_dependent_agents(
        self,
        tool_id: str,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetToolDependentAgentsResponseModel:
        """
        Get a list of agents depending on this tool

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many documents to return at maximum. Can not exceed 100, defaults to 30.

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

        Returns
        -------
        GetToolDependentAgentsResponseModel
            Successful Response

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

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.conversational_ai.tools.get_dependent_agents(
            tool_id="tool_id",
            cursor="cursor",
            page_size=1,
        )
        """
        _response = self._raw_client.get_dependent_agents(
            tool_id, cursor=cursor, page_size=page_size, request_options=request_options
        )
        return _response.data

    @property
    def executions(self):
        if self._executions is None:
            from .executions.client import ExecutionsClient  # noqa: E402

            self._executions = ExecutionsClient(client_wrapper=self._client_wrapper)
        return self._executions


class AsyncToolsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawToolsClient(client_wrapper=client_wrapper)
        self._client_wrapper = client_wrapper
        self._executions: typing.Optional[AsyncExecutionsClient] = None

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

        Returns
        -------
        AsyncRawToolsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        search: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        show_only_owned_documents: typing.Optional[bool] = None,
        created_by_user_id: typing.Optional[str] = None,
        types: typing.Optional[typing.Union[ToolTypeFilter, typing.Sequence[ToolTypeFilter]]] = None,
        sort_direction: typing.Optional[SortDirection] = None,
        sort_by: typing.Optional[ToolSortBy] = None,
        cursor: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolsResponseModel:
        """
        Get all available tools in the workspace.

        Parameters
        ----------
        search : typing.Optional[str]
            If specified, the endpoint returns only tools whose names start with this string.

        page_size : typing.Optional[int]
            How many documents to return at maximum. Can not exceed 100, defaults to 30.

        show_only_owned_documents : typing.Optional[bool]
            If set to true, the endpoint will return only tools owned by you (and not shared from somebody else). Deprecated: use created_by_user_id instead.

        created_by_user_id : typing.Optional[str]
            Filter tools by creator user ID. When set, only tools created by this user are returned. Takes precedence over show_only_owned_documents. Use '@me' to refer to the authenticated user.

        types : typing.Optional[typing.Union[ToolTypeFilter, typing.Sequence[ToolTypeFilter]]]
            If present, the endpoint will return only tools of the given types.

        sort_direction : typing.Optional[SortDirection]
            The direction to sort the results

        sort_by : typing.Optional[ToolSortBy]
            The field to sort the results by

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

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

        Returns
        -------
        ToolsResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tools.list(
                search="search",
                page_size=1,
                show_only_owned_documents=True,
                created_by_user_id="created_by_user_id",
                types=["webhook"],
                sort_direction="asc",
                sort_by="name",
                cursor="cursor",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            search=search,
            page_size=page_size,
            show_only_owned_documents=show_only_owned_documents,
            created_by_user_id=created_by_user_id,
            types=types,
            sort_direction=sort_direction,
            sort_by=sort_by,
            cursor=cursor,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self, *, request: ToolRequestModel, request_options: typing.Optional[RequestOptions] = None
    ) -> ToolResponseModel:
        """
        Add a new tool to the available tools in the workspace.

        Parameters
        ----------
        request : ToolRequestModel

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

        Returns
        -------
        ToolResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import (
            AsyncElevenLabs,
            ToolRequestModel,
            ToolRequestModelToolConfig_Client,
        )

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tools.create(
                request=ToolRequestModel(
                    tool_config=ToolRequestModelToolConfig_Client(
                        name="name",
                        description="description",
                        expects_response=False,
                    ),
                ),
            )


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

    async def get(
        self,
        tool_id: str,
        *,
        environment: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ToolResponseModel:
        """
        Get tool that is available in the workspace.

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        environment : typing.Optional[str]
            Environment whose values are used when the MCP server URL, headers, or auth connection reference environment variables. Mirrors the environment a conversation would run in; defaults to production.

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

        Returns
        -------
        ToolResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tools.get(
                tool_id="tool_id",
                environment="environment",
            )


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

    async def delete(
        self,
        tool_id: str,
        *,
        force: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Delete tool from the workspace.

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        force : typing.Optional[bool]
            If set to true, the tool will be deleted regardless of whether it is used by any agents and it will be removed from the dependent agents and branches.

        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.tools.delete(
                tool_id="tool_id",
                force=True,
            )


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

    async def update(
        self, tool_id: str, *, request: ToolRequestModel, request_options: typing.Optional[RequestOptions] = None
    ) -> ToolResponseModel:
        """
        Update tool that is available in the workspace.

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        request : ToolRequestModel

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

        Returns
        -------
        ToolResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import (
            AsyncElevenLabs,
            ToolRequestModel,
            ToolRequestModelToolConfig_Client,
        )

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tools.update(
                tool_id="tool_id",
                request=ToolRequestModel(
                    tool_config=ToolRequestModelToolConfig_Client(
                        name="name",
                        description="description",
                        expects_response=False,
                    ),
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(tool_id, request=request, request_options=request_options)
        return _response.data

    async def get_dependent_agents(
        self,
        tool_id: str,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetToolDependentAgentsResponseModel:
        """
        Get a list of agents depending on this tool

        Parameters
        ----------
        tool_id : str
            ID of the requested tool.

        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many documents to return at maximum. Can not exceed 100, defaults to 30.

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

        Returns
        -------
        GetToolDependentAgentsResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.conversational_ai.tools.get_dependent_agents(
                tool_id="tool_id",
                cursor="cursor",
                page_size=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_dependent_agents(
            tool_id, cursor=cursor, page_size=page_size, request_options=request_options
        )
        return _response.data

    @property
    def executions(self):
        if self._executions is None:
            from .executions.client import AsyncExecutionsClient  # noqa: E402

            self._executions = AsyncExecutionsClient(client_wrapper=self._client_wrapper)
        return self._executions
