#!/bin/bash

# Generate test certificates for check-in attendees on the staging server

echo "=== Generating Test Certificates on Staging Server ==="
echo "Remote host: 146.190.76.204"
echo "Remote user: roodev"
echo "==============================="

# Ensure test attendees exist first
echo "[1;33mChecking if test attendees exist...[0m"
ssh roodev@146.190.76.204 "cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html/ && wp post count tribe_tpp_attendees --path=/home/974670.cloudwaysapps.com/uberrxmprk/public_html/"

# If attendees don't exist, create them first
read -p "Do you want to create test attendees first? (y/n): " create_attendees
if [[ $create_attendees == "y" ]]; then
    echo "[1;33mCreating test attendees first...[0m"
    ./add-test-attendees.sh
fi

# Copy the PHP script to the server
echo "[1;33mCopying certificate generation script to server...[0m"
scp generate-test-certificates.php roodev@146.190.76.204:/home/974670.cloudwaysapps.com/uberrxmprk/public_html/

# Execute the script on the server
echo "[1;33mExecuting certificate generation script on server...[0m"
ssh roodev@146.190.76.204 "cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html/ && php generate-test-certificates.php"

# Clean up
echo "[1;33mCleaning up temporary files...[0m"
ssh roodev@146.190.76.204 "rm /home/974670.cloudwaysapps.com/uberrxmprk/public_html/generate-test-certificates.php"

echo "[0;32mTest certificate generation completed![0m"
echo "You can view and test certificates at: https://wordpress-974670-5399585.cloudwaysapps.com/certificate-reports/"
echo ""
echo "Features to test:"
echo "1. Certificate listing with pagination"
echo "2. Filtering by event"
echo "3. Filtering by attendee name/email (new feature)"
echo "4. Filtering by revocation status"
echo "5. Certificate downloading"
echo "6. Certificate email sending"