#!/bin/sh
# Local API v1: one impact, with no token. Default: print instructions only.
# Requires purchased Feel My Mac license and Local API selected.
# Experimentation/nonprofit API use: no additional fee. Integration inquiries:
# business@thehighjack.it
set -eu
if [ "${1:-}" != "--run" ]; then
  cat <<'PREVIEW'
Dry run: no network request or haptic output.
Run `sh impulse.sh --run` to send one natural impulse at 25% intensity.
It checks status, uses one UUID, and sends a final stop. There is no idle polling.
PREVIEW
  exit 0
fi
client_id=$(uuidgen)
base='http://127.0.0.1:59723'
post() {
  curl --silent --show-error --fail-with-body --max-time 1 --http1.1 \
    "$base$1" -H 'Content-Type: application/json' \
    -H "X-FMM-Client: $client_id" -H 'X-FMM-Client-Name: curl example' --data "$2"
}
cleanup() {
  post /v1/stop '{}' >/dev/null 2>&1 || true
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
curl --silent --show-error --fail-with-body --max-time 1 --http1.1 "$base/v1/status"
printf '\n'
post /v1/impulses '{"style":"natural","intensity":0.25}'
printf '\n'
