#!/bin/sh
# EMP CLI — Linux / macOS installer (via npm)
# One-liner:
#   curl -fsSL https://raw.githubusercontent.com/saintdevzz/emp-cli/main/install.sh | sh
# Or plain npm:
#   npm install -g emp-code
set -eu

echo "EMP CLI installer (Linux/macOS, via npm)"

if ! command -v node >/dev/null 2>&1; then
  echo "Node.js not found. Install Node.js 16+ from https://nodejs.org/"
  echo "  macOS:  brew install node"
  echo "  Linux:  curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - && sudo apt-get install -y nodejs"
  exit 1
fi
echo "Found Node $(node --version)"

if ! command -v npm >/dev/null 2>&1; then
  echo "npm not found — reinstall Node.js (npm ships with it)."
  exit 1
fi

echo "Installing emp-code via npm..."
npm install -g emp-code@latest

if command -v emp >/dev/null 2>&1; then
  echo "emp installed: $(command -v emp)"
else
  echo "emp not on PATH yet. Add npm global bin to PATH:"
  echo '  export PATH="$(npm config get prefix)/bin:$PATH"' >> "$HOME/.profile" 2>/dev/null || true
  echo "Then: source ~/.profile"
fi

echo ""
echo "Done! Try:"
echo "  emp --version"
echo '  emp ask "hi"       # HYBRA works instantly, no key needed'
echo "  emp update         # updates later"
