#!/bin/bash

# Setup script for GenAI Pentest Platform

set -e

echo "🚀 Setting up GenAI Pentest Platform..."

# Check Python version
python_version=$(python3 --version 2>&1 | awk '{print $2}')
required_version="3.8"

if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" != "$required_version" ]; then 
    echo "❌ Python 3.8 or higher is required. Found: $python_version"
    exit 1
fi

# Create virtual environment
echo "📦 Creating virtual environment..."
python3 -m venv venv
source venv/bin/activate

# Upgrade pip
pip install --upgrade pip

# Install dependencies
echo "📚 Installing dependencies..."
pip install -r requirements.txt

# Install package in development mode
echo "🔧 Installing package..."
pip install -e .

# Create necessary directories
echo "📁 Creating directories..."
mkdir -p logs data/reports data/cache data/models

# Copy environment file
if [ ! -f .env ]; then
    echo "🔐 Creating .env file..."
    cp .env.example .env
    echo "⚠️  Please edit .env and add your API keys"
fi

# Download NLTK data
echo "📊 Downloading NLTK data..."
python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')" 2>/dev/null || true

echo "✅ Setup complete!"
echo ""
echo "Next steps:"
echo "1. Edit .env and add your API keys"
echo "2. Run 'source venv/bin/activate' to activate the virtual environment"
echo "3. Run 'python -m src.cli --help' to see available commands"
echo "4. Run 'python -m src.web.app' to start the web interface"
