#!/usr/bin/env bash
# Run from the app checkout. Arguments: fresh app home, clone parent, phase.
# Both clones and every API read use the real GitCafe service, authenticated by CAFE_TOKEN.
set -eu
app_home=$1
clone_parent=$2
phase=$3
case "$phase" in
  clones)
    git clone https://git.cafe/%76ersecafe/ashlar.git "$clone_parent/escaped"
    git clone https://git.cafe/versecafe/ashlar.git "$clone_parent/plain"
    ;;
  escaped)
    git -C "$clone_parent/escaped" checkout main
    node apps/server/src/bin.ts project add "$clone_parent/escaped" --title 'Escaped HTTPS' --base-dir "$app_home"
    ;;
  plain)
    node apps/server/src/bin.ts project add "$clone_parent/plain" --title 'Plain HTTPS' --base-dir "$app_home"
    ;;
  thread)
    node apps/server/src/bin.ts thread start "$clone_parent/escaped" Hello --title 'Escaped PR lookup' --provider devReplay --model multi-turn --wait --json --base-dir "$app_home"
    git -C "$clone_parent/escaped" checkout chore/remove-harmont
    ;;
esac
