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

PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"

for program in python3 cargo node npm; do
  command -v "$program" >/dev/null || { echo "Missing required program: $program" >&2; exit 1; }
done

if command -v uv >/dev/null; then
  uv sync --project "$PROJECT_ROOT/backend" --extra test
else
  python3 -m venv "$PROJECT_ROOT/backend/.venv"
  "$PROJECT_ROOT/backend/.venv/bin/python" -m pip install -e "$PROJECT_ROOT/backend[test]"
fi

npm ci --prefix "$PROJECT_ROOT/dashboard"
cargo build --workspace --locked

echo "Polyform is ready. Run ./demo.sh, or target/debug/polyform --help"
