import subprocess
import sys
from module_utils import validate_dependencies

def install_dependencies():
    """Instala los módulos de Python necesarios."""
    required_modules = ["fusepy", "zstd", "numpy", "Pillow", "anytree"]
    missing_modules = []

    for module in required_modules:
        try:
            __import__(module)
            print(f"✓ {module} ya está instalado.")
        except ImportError:
            missing_modules.append(module)

    if not missing_modules:
        print("✅ Todas las dependencias ya están instaladas.")
        return True

    print(f"Instalando módulos faltantes: {', '.join(missing_modules)}")
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "install"] + missing_modules)
        print("✅ Módulos instalados correctamente.")
        return validate_dependencies()
    except Exception as e:
        print(f"❌ Error al instalar módulos: {e}")
        return False
