#!/bin/bash
# Startup script for SDF processing workflow

echo "🚀 Starting SDF Processing Workflow"
echo "===================================="

# Check if we're in a pixi environment
if [ -z "$PIXI_ENVIRONMENT_NAME" ]; then
    echo "📦 Activating pixi environment..."
    exec pixi run bash "$0" "$@"
    exit $?
fi

echo "✅ Pixi environment activated: $PIXI_ENVIRONMENT_NAME"

# Test the environment
echo "🧪 Running environment test..."
python test_environment.py

if [ $? -eq 0 ]; then
    echo ""
    echo "🎯 Ready to start! Choose your next step:"
    echo ""
    echo "1. Start Jupyter Notebook (recommended):"
    echo "   jupyter notebook notebooks/ --ip=0.0.0.0 --port=8888 --no-browser"
    echo ""
    echo "2. Start Jupyter Lab:"
    echo "   jupyter lab notebooks/ --ip=0.0.0.0 --port=8888 --no-browser"
    echo ""
    echo "3. Run extraction script directly:"
    echo "   python -c \"import papermill as pm; pm.execute_notebook('notebooks/01_extract_sdf_files.ipynb', 'extracted_output.ipynb')\""
    echo ""
    echo "4. Open interactive shell:"
    echo "   pixi shell"
    echo ""
    
    read -p "Enter your choice (1-4) or press Enter to start Jupyter: " choice
    
    case $choice in
        1)
            echo "📓 Starting Jupyter Notebook..."
            jupyter notebook notebooks/ --ip=0.0.0.0 --port=8888 --no-browser
            ;;
        2)
            echo "📓 Starting Jupyter Lab..."
            jupyter lab notebooks/ --ip=0.0.0.0 --port=8888 --no-browser
            ;;
        3)
            echo "🔄 Running extraction directly..."
            pixi add papermill
            python -c "import papermill as pm; pm.execute_notebook('notebooks/01_extract_sdf_files.ipynb', 'extracted_output.ipynb')"
            ;;
        4)
            echo "🐚 Opening interactive shell..."
            bash
            ;;
        *)
            echo "📓 Starting Jupyter Notebook (default)..."
            jupyter notebook notebooks/ --ip=0.0.0.0 --port=8888 --no-browser
            ;;
    esac
else
    echo "❌ Environment test failed. Please check the installation."
    exit 1
fi
