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

# Target-contract example. The local preview currently smokes the core event,
# timeline, search, Claim Boundary and Proof Packet routes only.
# Set BLACKBOARD_BASE_URL to a deployed Blackboard gateway when available.
BLACKBOARD_BASE_URL="${BLACKBOARD_BASE_URL:-}"
BLACKBOARD_TOKEN="${BLACKBOARD_TOKEN:-demo_token_not_a_secret}"

if [ -z "$BLACKBOARD_BASE_URL" ]; then
  echo "target-contract example: set BLACKBOARD_BASE_URL to a deployed Blackboard gateway" >&2
  exit 64
fi

if [ "$BLACKBOARD_TOKEN" = "demo_token_not_a_secret" ] && [[ "$BLACKBOARD_BASE_URL" != http://127.0.0.1:* && "$BLACKBOARD_BASE_URL" != http://localhost:* ]]; then
  echo "demo token is only allowed for local preview fixtures; use a real scoped token for hosted gateways" >&2
  exit 64
fi

curl -sS -X POST "$BLACKBOARD_BASE_URL/v1/risk/evaluations" \
  -H "Authorization: Bearer $BLACKBOARD_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: idem_demo_risk_eval_001" \
  --data @./risk-evaluation.demo.json
