#!/bin/bash

# Debug script to check event and attendee data on staging

source .env

echo "=== Debug Attendee Data ==="
echo "Target: $UPSKILL_STAGING_IP"
echo "==============================="

sshpass -p "$UPSKILL_STAGING_PASS" ssh -o StrictHostKeyChecking=no $UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP << 'EOF'

echo "=== 1. Check test_trainer user ID ==="
wp user get test_trainer --field=ID --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo ""
echo "=== 2. Check all events by test_trainer (ID 66) ==="
wp db query "SELECT ID, post_title, post_author, post_status, post_type, post_date FROM wp_posts WHERE post_type = 'tribe_events' AND post_author = 66 ORDER BY post_date DESC;" --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo ""
echo "=== 3. Check all recent tribe_events ==="
wp db query "SELECT ID, post_title, post_author, post_status, post_type, post_date FROM wp_posts WHERE post_type = 'tribe_events' AND post_date > '2025-08-10' ORDER BY post_date DESC;" --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo ""
echo "=== 4. Check existing attendees ==="
wp db query "SELECT p.ID, p.post_type, p.post_parent, p.post_status, p.post_title FROM wp_posts p WHERE p.post_type IN ('tribe_tpp_attendees', 'tec_tc_attendee') ORDER BY p.post_date DESC LIMIT 10;" --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo ""
echo "=== 5. Check wp_posts table structure for recent events ==="
wp db query "SELECT ID, post_title, post_author, post_status, post_type, post_date FROM wp_posts WHERE post_date > '2025-08-10' ORDER BY post_date DESC LIMIT 20;" --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html

EOF

echo ""
echo "Debug complete!"