#!/bin/bash
# Staging Deployment Configuration

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

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

source "$ENV_FILE"

# Verify required environment variables
if [ -z "$UPSKILL_STAGING_IP" ] || [ -z "$UPSKILL_STAGING_SSH_USER" ]; then
    echo "Error: Missing required environment variables"
    echo "Debug: UPSKILL_STAGING_IP=${UPSKILL_STAGING_IP:-<not set>}"
    echo "Debug: UPSKILL_STAGING_SSH_USER=${UPSKILL_STAGING_SSH_USER:-<not set>}"
    exit 1
fi

REMOTE_HOST="${UPSKILL_STAGING_IP}"
REMOTE_USER="${UPSKILL_STAGING_SSH_USER}"
REMOTE_PATH_BASE="/home/974670.cloudwaysapps.com/uberrxmprk/public_html"
PLUGIN_SLUG="hvac-community-events"
REMOTE_PLUGIN_PATH="${REMOTE_PATH_BASE}/wp-content/plugins/${PLUGIN_SLUG}/"
LOCAL_PLUGIN_PATH="$PROJECT_ROOT/wordpress-dev/wordpress/wp-content/plugins/${PLUGIN_SLUG}/"

# Verify plugin directory exists
if [ ! -d "$LOCAL_PLUGIN_PATH" ]; then
    echo "Error: Plugin directory not found at: $LOCAL_PLUGIN_PATH"
    echo "Please verify the plugin is in the correct location"
    exit 1
fi

# Deployment options
PURGE_BREEZE_CACHE=true
USE_ROOT=false
WP_CLI_PATH="wp"

# Debug output
echo "=== Deployment Configuration ==="
echo "Project root: $PROJECT_ROOT"
echo "Remote host: $REMOTE_HOST"
echo "Remote user: $REMOTE_USER"
echo "Remote path: $REMOTE_PLUGIN_PATH"
echo "Local plugin path: $LOCAL_PLUGIN_PATH"
echo "==============================="