"""Skill management CLI commands."""

from __future__ import annotations

import shutil
from pathlib import Path


def run_skill_interactive(show_help: bool = False) -> None:
    """Interactive skill setup - choose AI coding tool."""
    if show_help:
        print(_SKILL_HELP)
        return

    print("\n  Select your AI coding tool:\n")
    print("    1. Claude Code")
    print("    2. Cursor")
    print("    3. Other / Generic\n")

    choice = input("  Enter choice [1]: ").strip() or "1"

    if choice == "1":
        run_skill_install()
    elif choice == "2":
        print("\n  To integrate with Cursor, add the Bandito MCP server to your Cursor settings.")
        print("  Run: bandito setup config --mcp-enabled true")
        print("  Then add 'bandito' to your Cursor MCP servers config.\n")
    else:
        print("\n  For other AI coding tools, enable MCP in Bandito config:")
        print("    bandito setup config --mcp-enabled true")
        print("  Then add Bandito as an MCP server to your tool's configuration.\n")


_SKILL_HELP = """
bandito skill

  Interactively set up Bandito for your AI coding tool.

  Usage:
    bandito skill              # Interactive setup
    bandito skill --help       # Show this help
"""


def run_skill_install() -> None:
    """Install Claude Code skill for Bandito."""
    skill_dir = Path.home() / ".claude" / "skills" / "bandito"
    
    if skill_dir.exists():
        response = input(f"\n  Skill already exists at {skill_dir}.\n  Overwrite? [y/N]: ")
        if response.lower() != "y":
            print("  Cancelled.\n")
            return
        shutil.rmtree(skill_dir)
    
    skill_dir.mkdir(parents=True, exist_ok=True)
    
    source_skill = Path(__file__).parent.parent / "skills" / "bandito" / "SKILL.md"
    
    if not source_skill.exists():
        print(f"\n  Error: Skill template not found at {source_skill}\n")
        return
    
    shutil.copy2(source_skill, skill_dir / "SKILL.md")
    
    print(f"\n  ✓ Installed Bandito skill to {skill_dir}")
    print(f"\n  Invoke in Claude Code with: /bandito\n")
