import sys
import asyncio
import threading
import argparse

def run_discord():
    from botdiscord.bot import run_discord_bot
    run_discord_bot()

def run_telegram():
    from bottelegram.telegram_bot import run_telegram_bot
    run_telegram_bot()

def run_panel():
    import uvicorn
    from panel.main import app
    from botdiscord.config import load_config, get_web_config
    
    load_config()
    web_config = get_web_config()
    uvicorn.run(app, host=web_config.get("host", "0.0.0.0"), port=web_config.get("port", 8000))

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Bots de Traducción")
    parser.add_argument("--discord", action="store_true", help="Ejecutar solo Discord")
    parser.add_argument("--telegram", action="store_true", help="Ejecutar solo Telegram")
    parser.add_argument("--panel", action="store_true", help="Ejecutar solo Panel Web")
    args = parser.parse_args()
    
    threads = []
    
    if args.discord:
        run_discord()
    elif args.telegram:
        run_telegram()
    elif args.panel:
        run_panel()
    else:
        print("Iniciando todos los servicios...")
        t1 = threading.Thread(target=run_discord, daemon=True)
        t2 = threading.Thread(target=run_telegram, daemon=True)
        t3 = threading.Thread(target=run_panel, daemon=True)
        
        t1.start()
        t2.start()
        t3.start()
        
        print("✅ Discord Bot")
        print("✅ Telegram Bot")
        print("✅ Panel Web en http://localhost:8000")
        print("\nPresiona Ctrl+C para detener")
        
        try:
            t1.join()
            t2.join()
            t3.join()
        except KeyboardInterrupt:
            print("\nDeteniendo servicios...")
            sys.exit(0)
