#!/bin/bash
# Lead Flow Test Script
# Run this to verify: form → capture → database → dashboard

echo "🧪 Testing StartupLX Lead Flow Pipeline"
echo "=========================================="

# Test 1: Check if API endpoint exists
if [ -f "/var/www/html/api/capture.php" ]; then
    echo "✅ API endpoint deployed"
else
    echo "⚠️  Deploy capture.php to /public_html/api/"
fi

# Test 2: Test JSON validation
echo ""
echo "Testing JSON validation..."
php -r "
\$json = json_decode('{\"name\":\"Test\",\"email\":\"test@test.com\"}', true);
if (\$json) {
    echo \"✅ JSON parsing works\n\";
    echo \"Name: \" . \$json['name'] . \"\n\";
    echo \"Email: \" . \$json['email'] . \"\n\";
} else {
    echo \"❌ JSON parsing failed\n\";
}
"

# Test 3: Database connection (requires config)
echo ""
echo "Testing database connection..."
if [ -f "/var/www/html/.env" ]; then
    echo "✅ Environment file found"
else
    echo "⚠️  Create .env file with database credentials"
fi

# Test 4: Form submission simulation
echo ""
echo "Simulating form submission..."
curl -s -X POST http://localhost/api/lead-capture \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test User",
    "email": "test@example.com",
    "business_type": "tech-startup",
    "service_needed": "web-development",
    "notes": "Testing pipeline",
    "timestamp": "2026-08-29T00:00:00Z"
  }' | python3 -m json.tool

echo ""
echo "Pipeline test complete!"