#!/bin/bash

# Fix event dates to be in the future

# Get absolute path to this script's directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Navigate to wordpress-dev directory
cd "$(dirname "$SCRIPT_DIR")" || exit 1

# Load environment variables
ENV_FILE=".env"
if [ ! -f "$ENV_FILE" ]; then
    echo "Error: .env file not found at: $ENV_FILE"
    exit 1
fi

source "$ENV_FILE"

echo "=== Fixing Event Dates ==="
echo "Remote host: $UPSKILL_STAGING_IP"
echo "==============================="

# Fix event dates
sshpass -p "${UPSKILL_STAGING_PASS}" ssh -o StrictHostKeyChecking=no "${UPSKILL_STAGING_SSH_USER}@${UPSKILL_STAGING_IP}" <<'EOF'
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

# Update event dates to be in the future
echo "Updating event dates to future dates..."

# Event 5482: 1 month from now
wp post meta update 5482 _EventStartDate "2025-06-20 09:00:00" --allow-root
wp post meta update 5482 _EventEndDate "2025-06-20 17:00:00" --allow-root

# Event 5483: 2 months from now
wp post meta update 5483 _EventStartDate "2025-07-15 10:00:00" --allow-root
wp post meta update 5483 _EventEndDate "2025-07-15 18:00:00" --allow-root

# Event 5484: 3 months from now
wp post meta update 5484 _EventStartDate "2025-08-10 09:00:00" --allow-root
wp post meta update 5484 _EventEndDate "2025-08-10 16:00:00" --allow-root

# Event 5485: 4 months from now 
wp post meta update 5485 _EventStartDate "2025-09-05 13:00:00" --allow-root
wp post meta update 5485 _EventEndDate "2025-09-05 17:00:00" --allow-root

# Event 5486: 5 months from now
wp post meta update 5486 _EventStartDate "2025-10-20 08:00:00" --allow-root
wp post meta update 5486 _EventEndDate "2025-10-20 17:00:00" --allow-root

echo "Event dates updated!"

# Verify the updates
echo -e "\nVerifying updated dates:"
for EVENT_ID in 5482 5483 5484 5485 5486; do
    echo -n "Event $EVENT_ID: "
    wp post meta get $EVENT_ID _EventStartDate --allow-root
done

# Test query again
echo -e "\nTesting query with future dates:"
wp post list --post_type=tribe_events --author=17 --fields=ID,post_title,post_status --allow-root
EOF

echo "Fix completed!"