#!/bin/bash
#
# install-pip.sh - Install Python package dependencies for MarkiTect project
#
# USAGE
#
#    run "./install-pip.sh" after activating the virtual environment
#    or run "source .venv/bin/activate && ./install-pip.sh"
#

set -e  # Exit on any error

echo "🐍 MarkiTect Python Dependencies Installer"
echo "=========================================="
echo ""

# Check if virtual environment is active
if [ -z "$VIRTUAL_ENV" ]; then
    echo "⚠️  Virtual environment not detected"
    echo "   Checking for .venv directory..."

    if [ -d ".venv" ]; then
        echo "📁 Found .venv directory"
        echo "   Activating virtual environment..."
        source .venv/bin/activate
        echo "✅ Virtual environment activated: $VIRTUAL_ENV"
    else
        echo "❌ No .venv directory found"
        echo "   Please create a virtual environment first:"
        echo "   python3 -m venv .venv"
        echo "   source .venv/bin/activate"
        exit 1
    fi
else
    echo "✅ Virtual environment active: $VIRTUAL_ENV"
fi

echo ""
echo "📦 Installing project in development mode..."
pip install -e .

echo ""
echo "🧪 Installing testing dependencies..."
pip install pytest pytest-cov

echo ""
echo "🛠️  Installing development dependencies..."
pip install black flake8 mypy

echo ""
echo "🏗️  Installing build dependencies..."
pip install build

echo ""
echo "📋 Verifying installations..."
echo "   Python: $(python --version)"
echo "   pip: $(pip --version | cut -d' ' -f1-2)"
echo "   pytest: $(pytest --version | head -n1)"
echo "   black: $(black --version)"
echo "   flake8: $(flake8 --version | cut -d' ' -f1-2)"
echo "   mypy: $(mypy --version)"

echo ""
echo "📚 Installed packages:"
pip list --format=columns

echo ""
echo "✅ Python dependencies installation complete!"
echo ""
echo "🎯 Next steps:"
echo "   - Run tests: make test"
echo "   - Run linting: make lint"
echo "   - Format code: make format"
echo "   - Build package: make build"
