#!/usr/bin/env bash
# Run from the app checkout, after starting T3CODE_DEV_SEED=0 vp run dev.
# Usage: bash seed.sh T3_HOME WORKSPACE
set -eu
home_dir=$1
workspace=$2
mkdir -p "$workspace"
if ! git -C "$workspace" rev-parse --git-dir >/dev/null 2>&1; then
  git init --quiet --initial-branch=main "$workspace"
  git -C "$workspace" -c user.name=Evidence -c user.email=evidence@example.invalid commit --allow-empty -m 'Initial workspace' --quiet
fi
if output=$(node apps/server/src/bin.ts project add "$workspace" --base-dir "$home_dir" --title 'Plan approval demo' 2>&1); then
  echo 'Synthetic project registered.'
else
  case "$output" in
    *'active project already exists'*) echo 'Synthetic project already registered.' ;;
    *) printf '%s\n' "$output" >&2; exit 1 ;;
  esac
fi
