#!/usr/bin/env bash
set -euo pipefail
REPO=$(cd "$(dirname "$0")/../.." && pwd)
cd "$REPO"

OUT_DIR="artifacts/baselines/kitsune_2026_04_29"
mkdir -p "$OUT_DIR"
LOG="$OUT_DIR/master.log"
: > "$LOG"

PROTOCOLS_DEFAULT="iscxtor_within cicids_within cicddos_within forward_cross reverse_cross"
SEEDS_DEFAULT="42 43 44"
PROTOCOLS="${PROTOCOLS:-$PROTOCOLS_DEFAULT}"
SEEDS="${SEEDS:-$SEEDS_DEFAULT}"
N_TRAIN_CAP="${N_TRAIN_CAP:-5000}"

for protocol in $PROTOCOLS; do
  for seed in $SEEDS; do
    out_json="$OUT_DIR/${protocol}_seed${seed}.json"
    if [[ -f "$out_json" ]]; then
      echo "[skip] $out_json exists" | tee -a "$LOG"
      continue
    fi
    echo "=== protocol=$protocol seed=$seed n_train_cap=$N_TRAIN_CAP ===" | tee -a "$LOG"
    ts=$(date +%s)
    uv run --no-sync python scripts/baselines/run_kitsune.py \
      --protocol "$protocol" --seed "$seed" \
      --out-dir "$OUT_DIR" \
      --n-train-cap "$N_TRAIN_CAP" \
      2>&1 | tee -a "$LOG"
    te=$(date +%s)
    echo "[done] elapsed=$((te-ts))s  $out_json" | tee -a "$LOG"
  done
done
echo "ALL DONE"
