#!/bin/bash

echo "🧪 Testing local deployment simulation..."

# Create test directories
mkdir -p test-output/main
mkdir -p test-output/ghost-content

echo "📁 Simulating dual-output build..."

# Test 1: Check if ghost profile exists
if grep -q "ghost:" _quarto.yml; then
    echo "✅ Ghost profile configuration found"
else
    echo "❌ Ghost profile not found"
    exit 1
fi

# Test 2: Simulate content extraction
echo "🔍 Testing content extraction logic..."
cd ghost-upload

# Test with sample URL (without actually hitting network)
echo "📝 Testing Rust compilation and basic logic..."
if cargo check --quiet; then
    echo "✅ Rust code compiles successfully"
else
    echo "❌ Rust compilation failed"
    exit 1
fi

cd ..

# Test 3: Check if CI would work
echo "🔧 Validating CI configuration..."
if ./validate-ghost-extraction.sh > /dev/null 2>&1; then
    echo "✅ CI validation passed"
else
    echo "❌ CI validation failed"
    exit 1
fi

echo ""
echo "🎉 Local testing complete!"
echo ""
echo "📋 What happens in CI:"
echo "   1. Builds main site → public/"
echo "   2. Builds ghost content → public/ghost-content/"  
echo "   3. Rust extracts from ghost-content URLs"
echo "   4. Posts to Ghost blog with clean HTML"
echo ""
echo "🚀 Ready for branch testing in GitLab CI!"
echo "   • Download artifacts to see both outputs"
echo "   • Use manual trigger to test force-update"
echo "   • Check ghost-content/ folder structure"