"""Base command interface for Flow CLI.

Defines the contract for all CLI commands to ensure consistency.

Example implementation:
    class MyCommand(BaseCommand):
        @property
        def name(self) -> str:
            return "mycommand"
        
        @property
        def help(self) -> str:
            return "Do something useful"
        
        def get_command(self) -> click.Command:
            @click.command(name=self.name, help=self.help)
            def mycommand():
                console.print("Hello!")
            return mycommand
"""

from abc import ABC, abstractmethod

import click
from rich.console import Console

console = Console()


class BaseCommand(ABC):
    """Abstract base for CLI commands."""

    @property
    @abstractmethod
    def name(self) -> str:
        """Command name for CLI usage."""
        pass

    @property
    @abstractmethod
    def help(self) -> str:
        """Help text for the command."""
        pass

    @abstractmethod
    def get_command(self) -> click.Command:
        """Create and return click command."""
        pass

    def handle_error(self, error: Exception, exit_code: int = 1) -> None:
        """Display error and exit.
        
        Args:
            error: Exception to display
            exit_code: Process exit code
        """
        console.print(f"[red]Error:[/red] {error}")
        raise click.exceptions.Exit(exit_code)

    def handle_auth_error(self) -> None:
        """Display auth error and guide to init command."""
        console.print("[red]Authentication failed[/red]")
        console.print("\nPlease run [cyan]flow init[/cyan] to configure your credentials")
        raise click.exceptions.Exit(1)
