from __future__ import annotations

from typing import Any, Dict, Optional, TYPE_CHECKING

if TYPE_CHECKING:
    from socialrails.client import SocialRails, AsyncSocialRails


class AI:
    """Synchronous resource for AI content generation."""

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

    def generate(
        self,
        *,
        prompt: str,
        platform: Optional[str] = None,
        tone: Optional[str] = None,
    ) -> Dict[str, Any]:
        """Generate AI-powered social media content.

        Args:
            prompt: The content generation prompt (max 2000 characters).
            platform: Optional target platform to optimize content for.
            tone: Optional tone of voice (e.g. "professional", "casual", "friendly",
                "formal", "humorous", "inspirational", "educational", "persuasive").

        Returns:
            Dict with generated "content", "platform", and "tone".
        """
        body: Dict[str, Any] = {"prompt": prompt}
        if platform is not None:
            body["platform"] = platform
        if tone is not None:
            body["tone"] = tone
        return self._client._post("/ai/generate", body)


class AsyncAI:
    """Asynchronous resource for AI content generation."""

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

    async def generate(
        self,
        *,
        prompt: str,
        platform: Optional[str] = None,
        tone: Optional[str] = None,
    ) -> Dict[str, Any]:
        """Generate AI-powered social media content.

        Args:
            prompt: The content generation prompt (max 2000 characters).
            platform: Optional target platform to optimize content for.
            tone: Optional tone of voice (e.g. "professional", "casual", "friendly",
                "formal", "humorous", "inspirational", "educational", "persuasive").

        Returns:
            Dict with generated "content", "platform", and "tone".
        """
        body: Dict[str, Any] = {"prompt": prompt}
        if platform is not None:
            body["platform"] = platform
        if tone is not None:
            body["tone"] = tone
        return await self._client._post("/ai/generate", body)
