#!/bin/bash

echo "=== Verifying Master Dashboard Data After Migration ==="
echo "Date: $(date)"
echo

# SSH connection details
SERVER="146.190.76.204"
USER="roodev"

echo "🔍 Testing master dashboard data retrieval..."

# Execute verification via SSH
ssh ${USER}@${SERVER} << 'EOF'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo "=== Master Dashboard Data Verification ==="

echo "🔍 Step 1: Test the master dashboard data class directly..."
wp eval "
if (file_exists('wp-content/plugins/hvac-community-events/includes/class-hvac-master-dashboard-data.php')) {
    require_once 'wp-content/plugins/hvac-community-events/includes/class-hvac-master-dashboard-data.php';
    \$master_data = new HVAC_Master_Dashboard_Data();
    
    echo 'Testing master dashboard data methods:' . PHP_EOL;
    
    // Test trainer statistics
    \$trainer_stats = \$master_data->get_trainer_statistics();
    echo 'Total trainers found: ' . \$trainer_stats['total_trainers'] . PHP_EOL;
    
    echo 'Trainer breakdown:' . PHP_EOL;
    foreach (\$trainer_stats['trainer_data'] as \$trainer) {
        echo '  - ' . \$trainer->display_name . ' (' . \$trainer->user_email . ') - Events: ' . \$trainer->total_events . ', Revenue: $' . \$trainer->total_revenue . PHP_EOL;
    }
    
    // Test event totals
    echo PHP_EOL . 'Event statistics:' . PHP_EOL;
    echo 'Total events: ' . \$master_data->get_total_events_count() . PHP_EOL;
    echo 'Upcoming events: ' . \$master_data->get_upcoming_events_count() . PHP_EOL;
    echo 'Past events: ' . \$master_data->get_past_events_count() . PHP_EOL;
    
} else {
    echo 'Master dashboard data class not found!' . PHP_EOL;
}
"

echo
echo "🔍 Step 2: Verify current trainer role counts..."
echo "HVAC Trainers: $(wp user list --role=hvac_trainer --format=count)"
echo "HVAC Master Trainers: $(wp user list --role=hvac_master_trainer --format=count)"
echo "Legacy Event Trainers: $(wp user list --role=event_trainer --format=count)"

echo
echo "✅ Master dashboard data verification completed!"

EOF

echo "✅ Master dashboard verification completed!"