#!/usr/bin/env bash
# The scripted demo: show the rule, invoke both agents with the same request,
# then show in CloudTrail which agent was which. Each step's output is kept in
# build/demo/ for verify.sh and screenshots.sh.
#   EVIDENCE_WAIT  seconds to wait for CloudTrail delivery (default 900, 0 to skip waiting)
set -euo pipefail
cd "$(dirname "$0")/.."
PY=.venv/bin/python
OUT=build/demo
rm -rf "$OUT"; mkdir -p "$OUT"
since=$(date -u +%Y-%m-%dT%H:%M:%SZ)

step() { # step <file> <title> <agentctl args...>
  local file="$1" title="$2"; shift 2
  { echo "== $title"; echo; "$PY" poc/agentctl.py "$@"; } | tee "$OUT/$file.txt"
  echo
}

step 01-bucket-policy "1. The rule: one bucket policy, written against the agent's identity" policy
step 02-agentA "2. agentA is asked to read the object" invoke agentA
step 03-agentB "3. agentB gets the same request, with the same role" invoke agentB
step 04-cloudtrail "4. CloudTrail: which agent was which" evidence --since "$since" --wait "${EVIDENCE_WAIT:-900}"
