"""
Base class for all candy personality modules.
"""

from typing import Optional, Generator
from ..client import CandyClient

_shared_client = CandyClient()

class BaseModule:
    """
    Base class for all cedric-8EF personality modules.
    All modules share a single CandyClient instance for efficiency.
    """

    _personality: str = "full"

    @classmethod
    def ask(cls, prompt: str, context: Optional[str] = None) -> str:
        """
        Send a prompt and get a response string.

        Args:
            prompt: Your question or instruction.
            context: Optional extra context (documents, data, etc.)

        Returns:
            The AI response as a string.
        """
        result = _shared_client.ask(cls._personality, prompt, context=context, stream=False)
        return result.get("response", "")

    @classmethod
    def stream(cls, prompt: str, context: Optional[str] = None) -> Generator[str, None, None]:
        """
        Stream the response token by token.

        Args:
            prompt: Your question or instruction.
            context: Optional extra context.

        Yields:
            Response tokens as they arrive.
        """
        yield from _shared_client.ask(cls._personality, prompt, context=context, stream=True)

    @classmethod
    def ask_with_meta(cls, prompt: str, context: Optional[str] = None) -> dict:
        """
        Same as ask() but returns full metadata (quota remaining, hostname, etc.)
        """
        return _shared_client.ask(cls._personality, prompt, context=context, stream=False)

    @classmethod
    def quota(cls) -> dict:
        """Check your remaining daily quota."""
        return _shared_client.quota()
