#!/usr/bin/env python3
"""
🚀 Démarrage rapide de Web Sentinel
Utilisation: python quick_start.py [mode]

Modes disponibles:
  gui      - Interface graphique (défaut)
  cli      - Ligne de commande interactive 
  headless - Mode sans interface pour tests
  help     - Afficher l'aide complète
"""

import sys
import subprocess
from pathlib import Path

def show_help():
    """Afficher l'aide complète."""
    print(__doc__)
    print("\n📚 EXEMPLES D'UTILISATION:")
    print("  python quick_start.py gui           # Interface graphique")
    print("  python quick_start.py cli           # Mode interactif CLI")
    print("  python quick_start.py headless      # Test headless avec httpbin.org")
    print("\n🔧 COMMANDES DIRECTES:")
    print("  python -m web_sentinel.gui          # GUI directe")
    print("  python -m web_sentinel.cli example.com  # CLI directe")
    print("  python run_tests.py                 # Tests unitaires")
    print("  python install.py                   # Installation/vérification")

def launch_gui():
    """Lancer l'interface graphique."""
    print("🖥️ Lancement de l'interface graphique...")
    try:
        import tkinter
        subprocess.run([sys.executable, "-m", "web_sentinel.gui"])
    except ImportError:
        print("⚠️ tkinter non disponible, passage en mode headless...")
        launch_headless()

def launch_cli():
    """Lancer le CLI en mode interactif."""
    print("💻 Mode CLI interactif")
    print("Entrez un domaine à scanner (ou 'quit' pour quitter):")
    
    while True:
        try:
            domain = input("\n🌐 Domaine > ").strip()
            if domain.lower() in ['quit', 'exit', 'q']:
                break
            if not domain:
                continue
                
            print(f"🔍 Scan de {domain}...")
            subprocess.run([sys.executable, "-m", "web_sentinel.cli", domain])
            
        except KeyboardInterrupt:
            print("\n👋 Au revoir !")
            break

def launch_headless():
    """Lancer un test headless.""" 
    print("🤖 Mode headless - Test automatique")
    
    code = """
from web_sentinel.gui.headless import HeadlessWebSentinelGUI

app = HeadlessWebSentinelGUI()
result = app.run_headless_test(
    test_domains=['httpbin.org'],
    test_modules=['headers']
)

print('\\n📊 Résumé:')
for key, value in result.items():
    print(f'  {key}: {value}')
    
if result.get('scan_success'):
    print('\\n✅ Test headless réussi!')
else:
    print('\\n❌ Test headless échoué')
"""
    
    subprocess.run([sys.executable, "-c", code])

def main():
    """Point d'entrée principal."""
    
    # Vérifier si Web Sentinel est installé
    if not Path("web_sentinel").exists():
        print("❌ Web Sentinel non trouvé dans le répertoire courant")
        print("💡 Assurez-vous d'être dans le dossier web-sentinel/")
        return 1
    
    # Déterminer le mode
    mode = sys.argv[1] if len(sys.argv) > 1 else "gui"
    
    print("🛡️ WEB SENTINEL - Démarrage Rapide")
    print("=" * 45)
    
    if mode == "help" or mode == "-h" or mode == "--help":
        show_help()
    elif mode == "gui":
        launch_gui()
    elif mode == "cli":
        launch_cli()
    elif mode == "headless":
        launch_headless()
    else:
        print(f"❌ Mode '{mode}' non reconnu")
        show_help()
        return 1
    
    return 0

if __name__ == "__main__":
    sys.exit(main())