#!/usr/bin/env python3
"""
Script to install dependencies for the image detection backend
"""

import subprocess
import sys
import os

def install_requirements():
    """Install Python dependencies from requirements.txt"""
    try:
        # Get the directory of this script
        script_dir = os.path.dirname(os.path.abspath(__file__))
        requirements_path = os.path.join(script_dir, "requirements.txt")
        
        print("Installing Python dependencies...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", requirements_path])
        print("Python dependencies installed successfully!")
        
    except subprocess.CalledProcessError as e:
        print(f"Error installing dependencies: {e}")
        sys.exit(1)
    except FileNotFoundError:
        print("requirements.txt not found!")
        sys.exit(1)

def check_python_version():
    """Check if Python 3.8+ is installed"""
    if sys.version_info < (3, 8):
        print("Python 3.8 or higher is required!")
        sys.exit(1)
    print(f"Python version: {sys.version}")

if __name__ == "__main__":
    print("Checking Python version...")
    check_python_version()
    
    print("Installing image detection backend dependencies...")
    install_requirements()
    
    print("\nInstallation complete!")
    print("You can now start the image detection backend with:")
    print("  cd image-detection-backend")
    print("  python -m app.main")