#!/usr/bin/env bash
# Description: Run AEGIS (pure-rust + RustCrypto 0.6 wrappers) test suite with strict Clippy
set -euo pipefail

show_help() {
  cat <<'EOF'
Usage: scripts/Tests/tests-aegis.sh [--no-clippy]

Runs the AEGIS test suite in libs/aegis-quicfuscate with features:
  pure-rust rustcrypto-traits-06

Options:
  --no-clippy   Skip Clippy (default runs Clippy with -D warnings)
  -h, --help    Show this help and exit
EOF
}

NO_CLIPPY=0
for arg in "$@"; do
  case "$arg" in
    -h|--help|help)
      show_help
      exit 0
      ;;
    --no-clippy)
      NO_CLIPPY=1
      shift || true
      ;;
    *)
      echo "Unknown argument: $arg" >&2
      show_help
      exit 2
      ;;
  esac
done

SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "${SCRIPT_DIR}/../.." && pwd)"
AEGIS_DIR="${REPO_ROOT}/libs/aegis-quicfuscate"

FEATURES=${FEATURES:-"pure-rust rustcrypto-traits-06"}

echo "[AEGIS] Running cargo test with features: ${FEATURES}" >&2
(
  cd "${AEGIS_DIR}"
  cargo test --features "${FEATURES}"
)

if [[ "${NO_CLIPPY}" -eq 0 ]]; then
  echo "[AEGIS] Running cargo clippy -D warnings with features: ${FEATURES}" >&2
  (
    cd "${AEGIS_DIR}"
    cargo clippy --features "${FEATURES}" -- -D warnings
  )
else
  echo "[AEGIS] Skipping Clippy as requested (--no-clippy)" >&2
fi

echo "[AEGIS] Done." >&2
