#!/bin/bash

echo "📄 Creating Event Management Pages..."
echo "========================================"

# Connect to staging
ssh wp@upskill-staging.measurequick.com << 'EOF' 2>/dev/null || true
cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html

echo "🔧 Creating Create Event page..."
wp post create \
    --post_type=page \
    --post_title='Create Event' \
    --post_content='[hvac_create_event]' \
    --post_status=publish \
    --post_author=1 \
    --post_parent=$(wp post list --post_type=page --name=trainer --field=ID) \
    --post_name='create-event' \
    --meta_input='{"_wp_page_template":"templates/page-create-event.php"}' \
    --porcelain

echo "✅ Create Event page created"

echo "🔧 Creating Edit Event page..."
wp post create \
    --post_type=page \
    --post_title='Edit Event' \
    --post_content='[hvac_edit_event]' \
    --post_status=publish \
    --post_author=1 \
    --post_parent=$(wp post list --post_type=page --name=trainer --field=ID) \
    --post_name='edit-event' \
    --meta_input='{"_wp_page_template":"templates/page-edit-event.php"}' \
    --porcelain

echo "✅ Edit Event page created"

echo "🔄 Flushing rewrite rules..."
wp rewrite flush

echo "📋 Event pages created:"
wp post list --post_type=page --name='create-event' --fields=ID,post_title,post_name,post_status
wp post list --post_type=page --name='edit-event' --fields=ID,post_title,post_name,post_status

EOF

echo -e "\n✅ Event pages created successfully!"
echo "URLs:"
echo "  Create: https://upskill-staging.measurequick.com/trainer/create-event/"
echo "  Edit: https://upskill-staging.measurequick.com/trainer/edit-event/"