#!/usr/bin/env bash
# One-line installer for prompy:
#   curl -fsSL https://yariv.pages.dev/install.sh | bash
# Downloads the game and installs a `prompy` command into ~/.local/bin.
set -euo pipefail

URL="https://yariv.pages.dev/downloads/prompy.zip"

# On Windows, Python is usually `python` or `py`; `python3` may be a Store placeholder.
PY=""
for cand in python3 python "py -3"; do
  command -v "${cand%% *}" >/dev/null 2>&1 || continue
  if $cand -c 'import sys; sys.exit(sys.version_info[0] != 3)' >/dev/null 2>&1; then
    PY="$cand"
    break
  fi
done
[[ -n "$PY" ]] || { echo "prompy needs Python 3 - install it and try again" >&2; exit 1; }

TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT

echo "Downloading prompy..."
curl -fsSL "$URL" -o "$TMP/prompy.zip"
$PY -m zipfile -e "$TMP/prompy.zip" "$TMP"
bash "$TMP/prompy/install.sh"
