#!/bin/bash

# Site Crawler Setup Script
# This script sets up the environment for the website navigation crawler

set -e

echo "🌐 Setting up Website Navigation Crawler..."
echo "=========================================="

# Check if Python 3 is installed
if ! command -v python3 &> /dev/null; then
    echo "❌ Python 3 is not installed. Please install Python 3 first."
    exit 1
fi

echo "✅ Python 3 found: $(python3 --version)"

# Check if pip is installed
if ! command -v pip3 &> /dev/null; then
    echo "❌ pip3 is not installed. Please install pip3 first."
    exit 1
fi

echo "✅ pip3 found: $(pip3 --version)"

# Create virtual environment if it doesn't exist
if [ ! -d "crawler_env" ]; then
    echo "📦 Creating virtual environment..."
    python3 -m venv crawler_env
    echo "✅ Virtual environment created"
else
    echo "✅ Virtual environment already exists"
fi

# Activate virtual environment and install dependencies
echo "📦 Installing dependencies..."
source crawler_env/bin/activate
crawler_env/bin/python -m pip install --upgrade pip
crawler_env/bin/python -m pip install -r requirements.txt

echo "✅ Dependencies installed successfully"

# Make scripts executable
echo "🔧 Making scripts executable..."
chmod +x site_crawler.py
chmod +x demo_crawler.py
chmod +x example_usage.py

echo "✅ Scripts made executable"

# Test the installation
echo "🧪 Testing installation..."
crawler_env/bin/python demo_crawler.py

echo ""
echo "🎉 Setup completed successfully!"
echo ""
echo "📚 Usage:"
echo "   Basic crawl: crawler_env/bin/python site_crawler.py https://example.com"
echo "   Advanced: crawler_env/bin/python site_crawler.py https://example.com --max-depth 3 --max-pages 100"
echo "   Demo: crawler_env/bin/python demo_crawler.py"
echo "   Examples: crawler_env/bin/python example_usage.py"
echo ""
echo "📖 See README.md for detailed documentation" 