<?php
/**
 * Test Zoho Staging Mode
 * 
 * This script tests that staging mode correctly prevents production syncs
 */

// Load WordPress
require_once dirname(__DIR__, 5) . '/wp-load.php';

// Load our classes
require_once dirname(__DIR__) . '/includes/zoho/class-zoho-sync.php';
require_once dirname(__DIR__) . '/includes/zoho/class-zoho-crm-auth.php';

echo "\n=== Zoho Staging Mode Test ===\n\n";

// Check current site URL
$site_url = get_site_url();
$is_staging = strpos($site_url, 'upskillhvac.com') === false;

echo "Site URL: " . $site_url . "\n";
echo "Is Staging: " . ($is_staging ? 'YES' : 'NO') . "\n\n";

// Test sync operations
$sync = new HVAC_Zoho_Sync();

echo "Testing Event Sync...\n";
$event_results = $sync->sync_events();
print_r($event_results);
echo "\n";

echo "Testing User Sync...\n";
$user_results = $sync->sync_users();
print_r($user_results);
echo "\n";

echo "Testing Purchase Sync...\n";
$purchase_results = $sync->sync_purchases();
print_r($purchase_results);
echo "\n";

// Verify staging mode behavior
if ($is_staging) {
    echo "✓ Staging mode active - verifying no data was sent to Zoho\n";
    
    $checks = array(
        'Events' => $event_results,
        'Users' => $user_results,
        'Purchases' => $purchase_results
    );
    
    foreach ($checks as $type => $result) {
        if (isset($result['staging_mode']) && $result['staging_mode']) {
            echo "✓ $type sync correctly in staging mode\n";
        } else {
            echo "✗ ERROR: $type sync not in staging mode!\n";
        }
        
        if (isset($result['test_data'])) {
            echo "  - Test data preview available\n";
        }
    }
} else {
    echo "⚠️  Production mode active - data would be sent to Zoho\n";
}

echo "\n=== Test Complete ===\n";
?>