#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON_BIN="${PYTHON_BIN:-python3}"

usage() {
  cat <<'EOF'
Usage:
  ./setup.sh init [platform|all]
  ./setup.sh update [platform|all]

Platforms:
  antigravity
  codex
  opencode
  claude-code
  gemini-cli
  all

Commands:
  init    Rebuild generated platform environments from src/ without pulling.
  update  Run git pull --ff-only, then rebuild generated platform environments.
EOF
}

cmd="${1:-}"
platform="${2:-all}"

case "$cmd" in
  init)
    "$PYTHON_BIN" "$ROOT_DIR/src/scripts/update_platform_envs.py" --platform "$platform" --skip-pull
    ;;
  update)
    "$PYTHON_BIN" "$ROOT_DIR/src/scripts/update_platform_envs.py" --platform "$platform"
    ;;
  -h|--help|help|"")
    usage
    ;;
  *)
    echo "Unknown command: $cmd" >&2
    usage >&2
    exit 2
    ;;
esac
