# 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.composio_sync_response import ComposioSyncResponse
from ..types.composio_sync_status_response import ComposioSyncStatusResponse
from ..types.list_auth_configs_response import ListAuthConfigsResponse
from ..types.update_tool_status_response import UpdateToolStatusResponse
from .raw_client import AsyncRawAdminConnectorsClient, RawAdminConnectorsClient

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


class AdminConnectorsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAdminConnectorsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAdminConnectorsClient
        """
        return self._raw_client

    def trigger_connector_sync(
        self,
        *,
        force_full_sync: typing.Optional[bool] = None,
        api_key: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ComposioSyncResponse:
        """
        Trigger connector tool catalog sync.

        Syncs available tools into the local database.
        By default, uses incremental sync which only updates changed tools.
        Use force_full_sync=true to update all tools regardless of changes.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Args:
            force_full_sync: If true, skip incremental checks and update all tools

        Returns:
            Response with job_id and sync statistics

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        force_full_sync : typing.Optional[bool]
            Force full sync, ignoring incremental checks and interval

        api_key : typing.Optional[str]

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

        Returns
        -------
        ComposioSyncResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.admin_connectors.trigger_connector_sync()
        """
        _response = self._raw_client.trigger_connector_sync(
            force_full_sync=force_full_sync, api_key=api_key, request_options=request_options
        )
        return _response.data

    def get_sync_status(
        self, *, api_key: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ComposioSyncStatusResponse:
        """
        Get connector sync status and statistics.

        Returns information about the last sync, next scheduled sync,
        and tool counts.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Returns:
            Response with sync status information

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        api_key : typing.Optional[str]

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

        Returns
        -------
        ComposioSyncStatusResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.admin_connectors.get_sync_status()
        """
        _response = self._raw_client.get_sync_status(api_key=api_key, request_options=request_options)
        return _response.data

    def list_auth_configs(
        self, *, api_key: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ListAuthConfigsResponse:
        """
        List all connector auth configs in the project.

        This endpoint helps debug auth config issues and verify which configs
        are available for use. Useful for troubleshooting custom branding issues.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Returns:
            List of all auth configs with their IDs, toolkits, and types

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        api_key : typing.Optional[str]

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

        Returns
        -------
        ListAuthConfigsResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.admin_connectors.list_auth_configs()
        """
        _response = self._raw_client.list_auth_configs(api_key=api_key, request_options=request_options)
        return _response.data

    def update_tool_status(
        self,
        tool_key: str,
        *,
        is_enabled: bool,
        api_key: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateToolStatusResponse:
        """
        Enable or disable a connector tool.

        Controls whether a tool appears in the /v1/personal-connectors/available endpoint.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Args:
            tool_key: The tool key (e.g., "slack", "github", "notion")
            request: Request body with is_enabled boolean

        Returns:
            Updated tool status

        Raises:
            AuthenticationException: If admin API key is missing or invalid
            ResourceNotFoundException: If tool not found

        Parameters
        ----------
        tool_key : str

        is_enabled : bool

        api_key : typing.Optional[str]

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

        Returns
        -------
        UpdateToolStatusResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.admin_connectors.update_tool_status(
            tool_key="tool_key",
            is_enabled=True,
        )
        """
        _response = self._raw_client.update_tool_status(
            tool_key, is_enabled=is_enabled, api_key=api_key, request_options=request_options
        )
        return _response.data


class AsyncAdminConnectorsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAdminConnectorsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAdminConnectorsClient
        """
        return self._raw_client

    async def trigger_connector_sync(
        self,
        *,
        force_full_sync: typing.Optional[bool] = None,
        api_key: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ComposioSyncResponse:
        """
        Trigger connector tool catalog sync.

        Syncs available tools into the local database.
        By default, uses incremental sync which only updates changed tools.
        Use force_full_sync=true to update all tools regardless of changes.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Args:
            force_full_sync: If true, skip incremental checks and update all tools

        Returns:
            Response with job_id and sync statistics

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        force_full_sync : typing.Optional[bool]
            Force full sync, ignoring incremental checks and interval

        api_key : typing.Optional[str]

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

        Returns
        -------
        ComposioSyncResponse
            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.admin_connectors.trigger_connector_sync()


        asyncio.run(main())
        """
        _response = await self._raw_client.trigger_connector_sync(
            force_full_sync=force_full_sync, api_key=api_key, request_options=request_options
        )
        return _response.data

    async def get_sync_status(
        self, *, api_key: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ComposioSyncStatusResponse:
        """
        Get connector sync status and statistics.

        Returns information about the last sync, next scheduled sync,
        and tool counts.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Returns:
            Response with sync status information

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        api_key : typing.Optional[str]

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

        Returns
        -------
        ComposioSyncStatusResponse
            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.admin_connectors.get_sync_status()


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

    async def list_auth_configs(
        self, *, api_key: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ListAuthConfigsResponse:
        """
        List all connector auth configs in the project.

        This endpoint helps debug auth config issues and verify which configs
        are available for use. Useful for troubleshooting custom branding issues.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Returns:
            List of all auth configs with their IDs, toolkits, and types

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        api_key : typing.Optional[str]

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

        Returns
        -------
        ListAuthConfigsResponse
            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.admin_connectors.list_auth_configs()


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

    async def update_tool_status(
        self,
        tool_key: str,
        *,
        is_enabled: bool,
        api_key: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateToolStatusResponse:
        """
        Enable or disable a connector tool.

        Controls whether a tool appears in the /v1/personal-connectors/available endpoint.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Args:
            tool_key: The tool key (e.g., "slack", "github", "notion")
            request: Request body with is_enabled boolean

        Returns:
            Updated tool status

        Raises:
            AuthenticationException: If admin API key is missing or invalid
            ResourceNotFoundException: If tool not found

        Parameters
        ----------
        tool_key : str

        is_enabled : bool

        api_key : typing.Optional[str]

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

        Returns
        -------
        UpdateToolStatusResponse
            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.admin_connectors.update_tool_status(
                tool_key="tool_key",
                is_enabled=True,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_tool_status(
            tool_key, is_enabled=is_enabled, api_key=api_key, request_options=request_options
        )
        return _response.data
