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

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

BUNDLE_ROOT="${BUNDLE_ROOT:-$ROOT_DIR/../../rpki/target/live/20260316-112341-multi-final3}"
SUITE_OUT_DIR="${SUITE_OUT_DIR:-$ROOT_DIR/target/live/multi_rir_replay_runs}"
RIRS="${RIRS:-afrinic apnic arin lacnic ripe}"
CASE_SCRIPT="$ROOT_DIR/scripts/payload_replay/run_multi_rir_replay_case.sh"
SUMMARY_SCRIPT="$ROOT_DIR/scripts/payload_replay/write_multi_rir_summary.py"

mkdir -p "$SUITE_OUT_DIR"

for rir in $RIRS; do
  MULTI_RIR_OUT_DIR="$SUITE_OUT_DIR/$rir" \
    BUNDLE_ROOT="$BUNDLE_ROOT" \
    "$CASE_SCRIPT" "$rir" both
  echo "completed $rir" >&2
  echo >&2
 done

python3 "$SUMMARY_SCRIPT" \
  --case-root "$SUITE_OUT_DIR" \
  --out-md "$SUITE_OUT_DIR/multi_rir_summary.md" \
  --out-json "$SUITE_OUT_DIR/multi_rir_summary.json" \
  --rirs $RIRS >/dev/null

echo "== multi-RIR replay suite complete ==" >&2
echo "- suite_out_dir: $SUITE_OUT_DIR" >&2
echo "- summary_md: $SUITE_OUT_DIR/multi_rir_summary.md" >&2
echo "- summary_json: $SUITE_OUT_DIR/multi_rir_summary.json" >&2
