"""Main CLI entry point for RoastBuddy."""

import click
from rich.console import Console

console = Console()


@click.group()
@click.version_option(version="0.1.0", prog_name="roastbuddy")
def main():
    """🔥 RoastBuddy - Your witty coding companion!
    
    Roasts, praises, and tracks your development journey.
    """
    pass


@main.command()
@click.option("--path", default=".", help="Path to git repository")
def init(path):
    """Initialize RoastBuddy in a git repository."""
    from roastbuddy.core.initializer import initialize_roastbuddy
    
    console.print("[bold cyan]🔥 Initializing RoastBuddy...[/bold cyan]")
    success = initialize_roastbuddy(path)
    
    if success:
        console.print("[bold green]✅ RoastBuddy is ready to roast![/bold green]")
        console.print("\n💡 Try: [bold]roastbuddy status[/bold]")
    else:
        console.print("[bold red]❌ Failed to initialize RoastBuddy[/bold red]")


@main.command()
def status():
    """Show current streaks and recent activity."""
    from roastbuddy.core.status import show_status
    
    console.print("[bold cyan]📊 RoastBuddy Status[/bold cyan]\n")
    show_status()


@main.command()
@click.option("--last", "-l", is_flag=True, help="Roast the last commit")
def roast(last):
    """Roast your code with humor."""
    from roastbuddy.core.roaster import roast_code
    
    console.print("[bold red]🔥 Preparing your roast...[/bold red]\n")
    roast_code(last_commit=last)


@main.command()
@click.option("--last", "-l", is_flag=True, help="Praise the last commit")
def praise(last):
    """Get some well-deserved praise!"""
    from roastbuddy.core.roaster import praise_code
    
    console.print("[bold green]✨ Preparing your praise...[/bold green]\n")
    praise_code(last_commit=last)


@main.command()
@click.option("--type", "-t", type=click.Choice(["all", "clean", "daily", "test"]), 
              default="all", help="Streak type to display")
def streak(type):
    """View your coding streaks."""
    from roastbuddy.core.streaks import show_streaks
    
    console.print("[bold magenta]🔥 Your Coding Streaks[/bold magenta]\n")
    show_streaks(streak_type=type)


@main.command()
@click.option("--limit", "-n", default=10, help="Number of entries to show")
def history(limit):
    """View roast and praise history."""
    from roastbuddy.core.history import show_history
    
    console.print("[bold cyan]📜 RoastBuddy History[/bold cyan]\n")
    show_history(limit=limit)


@main.command()
@click.option("--format", "-f", type=click.Choice(["linkedin", "twitter", "github"]), 
              default="linkedin", help="Output format")
def share(format):
    """Generate shareable social media content."""
    from roastbuddy.core.share import generate_shareable
    
    console.print(f"[bold cyan]📤 Generating {format} content...[/bold cyan]\n")
    generate_shareable(format_type=format)


@main.command()
@click.option("--show", is_flag=True, help="Show current configuration")
@click.option("--set", "set_value", nargs=2, help="Set config value (key value)")
def config(show, set_value):
    """Manage RoastBuddy configuration."""
    from roastbuddy.core.config import show_config, set_config
    
    if show:
        show_config()
    elif set_value:
        key, value = set_value
        set_config(key, value)
    else:
        console.print("[yellow]Use --show or --set to manage configuration[/yellow]")


if __name__ == "__main__":
    main()
