#!/usr/bin/env python3
"""Check all required dependencies are installed."""
import sys

def check_import(module_name, package_name=None):
    """Try to import a module and report status."""
    package = package_name or module_name
    try:
        __import__(module_name)
        print(f"✅ {package}")
        return True
    except ImportError as e:
        print(f"❌ {package}: {e}")
        return False

def main():
    """Check all dependencies."""
    print("🔍 Checking Python dependencies...\n")

    dependencies = [
        # Web Framework
        ("fastapi", "fastapi"),
        ("uvicorn", "uvicorn"),
        ("multipart", "python-multipart"),

        # Database
        ("sqlalchemy", "sqlalchemy"),
        ("psycopg2", "psycopg2-binary"),
        ("pgvector.sqlalchemy", "pgvector"),
        ("alembic", "alembic"),

        # Audio Processing
        ("librosa", "librosa"),
        ("soundfile", "soundfile"),
        ("audioread", "audioread"),
        ("mutagen", "mutagen"),

        # Scientific
        ("numpy", "numpy"),
        ("scipy", "scipy"),

        # Configuration
        ("pydantic", "pydantic"),
        ("pydantic_settings", "pydantic-settings"),
        ("dotenv", "python-dotenv"),
        ("email_validator", "email-validator"),

        # Authentication
        ("jose", "python-jose"),
        ("passlib", "passlib"),

        # Utilities
        ("aiofiles", "aiofiles"),
        ("httpx", "httpx"),

        # Essentia (optional)
        ("essentia.standard", "essentia-tensorflow"),
    ]

    all_ok = True
    for module, package in dependencies:
        if not check_import(module, package):
            all_ok = False

    print("\n" + "="*50)
    if all_ok:
        print("✅ All dependencies installed!")
        return 0
    else:
        print("❌ Some dependencies are missing")
        print("\nInstall missing dependencies with:")
        print("  pip install -r requirements.txt")
        return 1

if __name__ == "__main__":
    sys.exit(main())
