#!/bin/sh
# AstraNL first success in one call, curl only. No key, no signup. Needs curl and jq.
set -e
U='https://astranl.com/mcp/streamable?profile=core'
# 1. one call: a planning estimate with a signed receipt
ANSWER=$(curl -s "$U" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"astranl_renovation_estimate_nl","arguments":{"category":"painting","area_m2":30,"location":"Utrecht"}}}' \
  | sed -n 's/^data: //p' | jq -r '.result.content[0].text')
echo "$ANSWER" | jq '{range: .answer_meta.range | {low, typical, high}, receipt: .receipt | {reference, state}}'
REF=$(echo "$ANSWER" | jq -r .receipt.reference)
# 2. verify the receipt online (plain HTTPS GET, no MCP needed).
# Signed and included: PASS (L3). Signed, inclusion follows with the next tree head: SIGNED_PENDING_INCLUSION (L2).
curl -s "https://astranl.com/api/astralock/verify/$REF" | jq '{verdict: (if .found and .content_integrity == "PASS" and .envelope_integrity == "PASS" and .signature == "PASS"
  then (if .merkle_inclusion == "PASS" then "PASS" else "SIGNED_PENDING_INCLUSION" end) else "FAIL" end), proof_level}'
