#!/usr/bin/env bash
# Parallel deployment wrapper for Besu nodes
# Enhances deploy-besu-nodes.sh with parallel container creation

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

source "$PROJECT_ROOT/lib/common.sh" 2>/dev/null || true
source "$PROJECT_ROOT/lib/batch-parallel.sh" 2>/dev/null || true

# Load configuration
load_config "$PROJECT_ROOT/config/proxmox.conf" 2>/dev/null || true

# Check if parallel deployment is enabled
if [[ "${PARALLEL_DEPLOY:-true}" == "true" ]] && [[ -f "$PROJECT_ROOT/lib/batch-parallel.sh" ]]; then
    log_info "Parallel deployment enabled (max: ${MAX_PARALLEL_CREATE:-10})"
    # Use enhanced parallel deployment
    export USE_PARALLEL_DEPLOY=true
else
    log_info "Using sequential deployment"
    export USE_PARALLEL_DEPLOY=false
fi

# Call the main deployment script
exec "$SCRIPT_DIR/deploy-besu-nodes.sh" "$@"

