from __future__ import annotations

from typing import Any, Dict, List, TYPE_CHECKING

if TYPE_CHECKING:
    from socialrails.client import SocialRails, AsyncSocialRails


class Accounts:
    """Synchronous resource for managing connected social media accounts."""

    def __init__(self, client: SocialRails) -> None:
        self._client = client

    def list(self) -> List[Dict[str, Any]]:
        """List all connected social media accounts.

        Returns:
            List of account objects with id, provider, name, status, and connected_at.
        """
        return self._client._get("/accounts")

    def get_settings(self, account_id: str) -> Dict[str, Any]:
        """Get platform capabilities and default settings for an account.

        Args:
            account_id: The UUID of the connected account.

        Returns:
            Dict with account_id, platform, capabilities, defaults, and available_tools.
        """
        return self._client._get(f"/accounts/{account_id}/settings")

    def trigger_tool(self, account_id: str, tool: str) -> Dict[str, Any]:
        """Trigger a platform discovery tool on an account.

        Args:
            account_id: The UUID of the connected account.
            tool: The tool name to trigger (e.g. "pages", "boards", "communities").

        Returns:
            Dict with tool name, platform, and results list.
        """
        return self._client._post(f"/accounts/{account_id}/tools", {"tool": tool})


class AsyncAccounts:
    """Asynchronous resource for managing connected social media accounts."""

    def __init__(self, client: AsyncSocialRails) -> None:
        self._client = client

    async def list(self) -> List[Dict[str, Any]]:
        """List all connected social media accounts.

        Returns:
            List of account objects with id, provider, name, status, and connected_at.
        """
        return await self._client._get("/accounts")

    async def get_settings(self, account_id: str) -> Dict[str, Any]:
        """Get platform capabilities and default settings for an account.

        Args:
            account_id: The UUID of the connected account.

        Returns:
            Dict with account_id, platform, capabilities, defaults, and available_tools.
        """
        return await self._client._get(f"/accounts/{account_id}/settings")

    async def trigger_tool(self, account_id: str, tool: str) -> Dict[str, Any]:
        """Trigger a platform discovery tool on an account.

        Args:
            account_id: The UUID of the connected account.
            tool: The tool name to trigger (e.g. "pages", "boards", "communities").

        Returns:
            Dict with tool name, platform, and results list.
        """
        return await self._client._post(f"/accounts/{account_id}/tools", {"tool": tool})
