#!/bin/bash

# Create Communication Templates page on staging server

echo "Creating Communication Templates page on staging server..."

# Check if the page already exists
PAGE_EXISTS=$(ssh roodev@146.190.76.204 "cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html && wp post list --post_type=page --title='Communication Templates' --field=ID")

if [ -n "$PAGE_EXISTS" ]; then
    echo "Communication Templates page already exists with ID: $PAGE_EXISTS"
    exit 0
fi

# Create the page with the shortcode
PAGE_ID=$(ssh roodev@146.190.76.204 "cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html && wp post create --post_type=page --post_title='Communication Templates' --post_status=publish --post_content='[hvac_communication_templates]' --porcelain")

if [ $? -eq 0 ] && [ -n "$PAGE_ID" ]; then
    echo "✓ Communication Templates page created successfully"
else
    echo "✗ Failed to create Communication Templates page"
    exit 1
fi

# Verify the page was created
VERIFY_ID=$(ssh roodev@146.190.76.204 "cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html && wp post list --post_type=page --name=communication-templates --field=ID")

if [ -n "$VERIFY_ID" ]; then
    echo "✓ Page created with ID: $PAGE_ID"
    echo "✓ URL: https://upskill-staging.measurequick.com/communication-templates/"
else
    echo "✗ Failed to verify page creation"
    exit 1
fi