"""Anthropic Setup Token authentication handler."""

from typing import Any, Dict

from rich.console import Console

from kabot.auth.handlers.base import AuthHandler
from kabot.auth.utils import secure_input

console = Console()


class AnthropicTokenHandler(AuthHandler):
    """Handler for Anthropic Setup Token authentication."""

    @property
    def name(self) -> str:
        return "Anthropic (Setup Token)"

    def authenticate(self) -> Dict[str, Any]:
        """Execute Anthropic Setup Token authentication flow."""
        console.print("\n[bold]Anthropic Setup Token[/bold]")
        console.print("1. Install the Claude CLI if you haven't already.")
        console.print("2. Run the command: [cyan]claude setup-token[/cyan]")
        console.print("3. Copy the token generated by the CLI.\n")

        # Manual input
        token = secure_input("Enter Anthropic Setup Token")

        if not token:
            return None

        return {"providers": {"anthropic": {"setup_token": token}}}
