# 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.connector_tool_invoke_response import ConnectorToolInvokeResponse
from .raw_client import AsyncRawConnectorsToolsClient, RawConnectorsToolsClient

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


class ConnectorsToolsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawConnectorsToolsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawConnectorsToolsClient
        """
        return self._raw_client

    def invoke_connector_tool(
        self,
        *,
        tool_name: str,
        arguments: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ConnectorToolInvokeResponse:
        """
        Execute a personal connector tool (IMAP, Gmail, ClickUp, Google Drive, etc.) without routing through an LLM. Returns the raw tool result synchronously.

        No LLM token usage, no thread creation, no background jobs. Authentication, credential resolution, and rate limiting apply identically to the agentic loop.

        **tool_name** must match a tool the authenticated user has connected for this organization. Use `GET /v1/personal-connectors/` to list connected connectors.

        Parameters
        ----------
        tool_name : str
            Full connector tool name including the connector prefix. Examples: 'imap_read_email', 'imap_list_emails', 'clickup_filter_tasks'. The prefix must match the connector type (imap_, apple_calendar_, etc.) or a connector tool key the user has connected.

        arguments : typing.Optional[typing.Dict[str, typing.Any]]
            Tool-specific arguments. Schema varies by tool.

        organization_id : typing.Optional[str]
            Target organization ID. Required when authenticating with a multi-org API key. Inferred automatically for Bearer token auth and single-org keys.

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

        Returns
        -------
        ConnectorToolInvokeResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.connectors_tools.invoke_connector_tool(
            tool_name="tool_name",
        )
        """
        _response = self._raw_client.invoke_connector_tool(
            tool_name=tool_name, arguments=arguments, organization_id=organization_id, request_options=request_options
        )
        return _response.data


class AsyncConnectorsToolsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawConnectorsToolsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawConnectorsToolsClient
        """
        return self._raw_client

    async def invoke_connector_tool(
        self,
        *,
        tool_name: str,
        arguments: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        organization_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ConnectorToolInvokeResponse:
        """
        Execute a personal connector tool (IMAP, Gmail, ClickUp, Google Drive, etc.) without routing through an LLM. Returns the raw tool result synchronously.

        No LLM token usage, no thread creation, no background jobs. Authentication, credential resolution, and rate limiting apply identically to the agentic loop.

        **tool_name** must match a tool the authenticated user has connected for this organization. Use `GET /v1/personal-connectors/` to list connected connectors.

        Parameters
        ----------
        tool_name : str
            Full connector tool name including the connector prefix. Examples: 'imap_read_email', 'imap_list_emails', 'clickup_filter_tasks'. The prefix must match the connector type (imap_, apple_calendar_, etc.) or a connector tool key the user has connected.

        arguments : typing.Optional[typing.Dict[str, typing.Any]]
            Tool-specific arguments. Schema varies by tool.

        organization_id : typing.Optional[str]
            Target organization ID. Required when authenticating with a multi-org API key. Inferred automatically for Bearer token auth and single-org keys.

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

        Returns
        -------
        ConnectorToolInvokeResponse
            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.connectors_tools.invoke_connector_tool(
                tool_name="tool_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.invoke_connector_tool(
            tool_name=tool_name, arguments=arguments, organization_id=organization_id, request_options=request_options
        )
        return _response.data
