#!/usr/bin/env bash
set -euo pipefail

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

targets=(
  .env.example
  README.md
  INSTALL_CN.md
  SERVER_POOL_INSTALL_CN.md
  TOKENOMICS.md
  RELEASE_RUNBOOK.md
  install.sh
  scripts
  templates
  files/docs-site
  preview
)

pattern='(^|[^A-Za-z0-9])(HC|Hcash|Hypercash|YiIMP|yiimp|HC[[:space:]]+pool|HC池|旧[[:space:]]*HC)([^A-Za-z0-9]|$)'

echo "== Vexon clean deployment audit =="
echo "Scanning customer-facing deployment files for legacy pool names..."
echo

matches=0
for target in "${targets[@]}"; do
  [[ -e "$target" ]] || continue
  if rg -n --hidden \
    --glob '!*.png' \
    --glob '!*.jpg' \
    --glob '!*.jpeg' \
    --glob '!*.gif' \
    --glob '!*.ico' \
    --glob '!scripts/audit-vexon-clean.sh' \
    -e "$pattern" "$target"; then
    matches=1
  fi
done

if (( matches != 0 )); then
  echo
  echo "[FAIL] customer-facing deployment files contain legacy pool naming." >&2
  exit 1
fi

echo "[OK] customer-facing deployment files are clean Vexon deployment material."
