#!/usr/bin/env bash
# Full bidirectional bridge configuration (Ethereum mainnet ↔ Chain 138).
# Legacy scripts under scripts/configuration/configure-chain138-* were removed; this delegates to deployment helpers.

set -euo pipefail

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

if [[ -f "$SCRIPT_DIR/../lib/deployment/dotenv.sh" ]]; then
  # shellcheck disable=SC1090
  source "$SCRIPT_DIR/../lib/deployment/dotenv.sh"
  load_deployment_env --repo-root "$PROJECT_ROOT"
elif [[ -f "$PROJECT_ROOT/.env" ]]; then
  set -a
  # shellcheck disable=SC1090
  source "$PROJECT_ROOT/.env"
  set +a
fi

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }

log_info "=== Mainnet ↔ Chain 138 (WETH9/WETH10 bridges) ==="
bash "$PROJECT_ROOT/scripts/deployment/execute-bridge-config.sh" || log_warn "execute-bridge-config.sh exited non-zero (review output)."

log_info "=== Config-ready chains (Gnosis/Cronos/Celo/Wemix) ==="
log_info "When bridge addresses are in .env, run: scripts/deployment/complete-config-ready-chains.sh"

log_info "=== Optional verification ==="
if [[ -x "$PROJECT_ROOT/scripts/verify-bridge-setup-checklist.sh" ]]; then
  bash "$PROJECT_ROOT/scripts/verify-bridge-setup-checklist.sh" || log_warn "Checklist reported issues (non-fatal)."
else
  log_warn "verify-bridge-setup-checklist.sh not found or not executable."
fi

log_success "=== Done ==="
