#!/usr/bin/env bash
set -euo pipefail
# Prerequisite: pair Android Pixel 9 (API 36), light app theme, 1080x2424.
# Start each commit from fresh T3 state with T3CODE_DEV_SEED=0.
# Generate images with seed-images.py, download both to Android, then:
# Add project and start replay thread using the same CLI on each commit:
# node apps/server/src/bin.ts project add "$WORKSPACE" --title "Media gallery proof" --base-dir "$T3_HOME"
# node apps/server/src/bin.ts thread start "$WORKSPACE" "Ready for two images" --title "Sent image gallery" --provider devReplay --model multi-turn --wait --json --base-dir "$T3_HOME"
# In that thread: Add attachment > Photo Library; select blue then orange; Done; Send.
# Wait for delivered thumbnails. The replay provider rejects the image turn,
# but both uploaded images are persisted and the sent-image viewer is usable.
# Tap first sent thumbnail before recording (avoids environment details in header).
: "${SESSION:?}" "${OUTPUT_ROOT:?}" "${SIDE:?}"
out="$OUTPUT_ROOT/$(date -u +%Y%m%dT%H%M%SZ)-$SIDE"
mkdir -p "$out"
agent-device snapshot -i --session "$SESSION"
agent-device record start "$out/swipe.mp4" --hide-touches --session "$SESSION"
agent-device screenshot "$out/first.png" --session "$SESSION"
agent-device swipe 900 1200 180 1200 --session "$SESSION"
agent-device snapshot -i --session "$SESSION"
agent-device screenshot "$out/second-a.png" --session "$SESSION"
agent-device wait 500 --session "$SESSION"
agent-device screenshot "$out/second.png" --session "$SESSION"
# Base has only Close; head also retains Media actions.
if [ "$SIDE" = head ]; then
  agent-device press 'label="Media actions"' --settle --session "$SESSION"
  agent-device press 'text="Share"' --settle --session "$SESSION"
  agent-device wait 'text="Sharing image"' 20000 --session "$SESSION"
  agent-device screenshot "$out/share.png" --session "$SESSION"
fi
agent-device record stop --session "$SESSION"
