from abc import ABC, abstractmethod
from typing import Optional


class UserInterfaceAdapter(ABC):
    """Base adapter for user interaction. Implementations may be sync or async.

    Methods:
      - supports_sync: whether adapter can synchronously ask and return an answer
      - ask_sync(prompt): return answer (or raise NotImplementedError)
      - ask_async(prompt): return a token to await
    """
    supports_sync: bool = False

    def ask_sync(self, prompt: str) -> str:
        raise NotImplementedError()

    def ask_async(self, prompt: str) -> str:
        """Return a token representing the pending question."""
        raise NotImplementedError()


class CLIAdapter(UserInterfaceAdapter):
    supports_sync = True

    def ask_sync(self, prompt: str) -> str:
        return input(f"🤔  {prompt} ")


class WebAdapter(UserInterfaceAdapter):
    """Web adapter is not sync; it relies on token/resume flow.
    The actual pending store is managed in `agent_src.ui_state`/`web.py`.
    """
    supports_sync = False

    def ask_async(self, prompt: str) -> str:
        # WebAdapter doesn't itself store state; AskUserTool will create token.
        raise NotImplementedError()
