#!/usr/bin/env bash
# Create a fresh, git-initialized sandbox copy of the Eval B fixture.
# Usage: sandbox <W1|W2|W3|R1|R2|R3|R4|R4-nograph> <dest-dir>
#
# Only R4 keeps graphify-out/ (the graph-layer scenario). R4-nograph is the
# degradation variant: same scenario, graph deliberately absent.
set -euo pipefail

SCENARIO="${1:?usage: sandbox <scenario> <dest-dir>}"
DEST="${2:?usage: sandbox <scenario> <dest-dir>}"
EVAL_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FIXTURE="$EVAL_ROOT/fixture/project"

case "$SCENARIO" in
  W1|W2|W3|R1|R2|R3|R4-nograph) GRAPH=no ;;
  R4)                           GRAPH=yes ;;
  *) echo "unknown scenario: $SCENARIO" >&2; exit 2 ;;
esac

if [ "$GRAPH" = yes ] && [ ! -f "$FIXTURE/graphify-out/graph.json" ]; then
  echo "fixture graph missing — run eval-b/bin/build-fixture-graph first" >&2
  exit 2
fi

if [ -e "$DEST" ]; then echo "refusing to overwrite existing $DEST" >&2; exit 2; fi
mkdir -p "$DEST"
cp -r "$FIXTURE/." "$DEST/"
[ "$GRAPH" = no ] && rm -rf "$DEST/graphify-out"
rm -rf "$DEST/.os-adr"

git -C "$DEST" init -q
git -C "$DEST" add -A
git -C "$DEST" -c user.email=eval@local -c user.name=eval commit -qm "fixture baseline"
echo "$DEST"
