#!/usr/bin/env bash
# AiGentsy Stamp — Create a verifiable proof with one curl command.
# No signup, no API key, no install needed.
#
# Usage:
#     bash stamp_curl.sh
#     # or
#     chmod +x stamp_curl.sh && ./stamp_curl.sh

BASE="https://aigentsy-ame-runtime.onrender.com"

echo "=== AiGentsy Stamp ==="
echo ""
echo "1. Creating proof..."

RESULT=$(curl -s -X POST "$BASE/protocol/stamp" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "curl_demo",
    "description": "Completed deliverable — verified via AiGentsy Settlement Protocol"
  }')

DEAL_ID=$(echo "$RESULT" | grep -o '"deal_id":"[^"]*"' | head -1 | cut -d'"' -f4)

echo "   deal_id: $DEAL_ID"
echo ""

if [ -z "$DEAL_ID" ]; then
  echo "Error: no deal_id returned"
  echo "$RESULT"
  exit 1
fi

echo "2. Verifying..."
VERIFY=$(curl -s "$BASE/proof/$DEAL_ID/verify")
echo "   $VERIFY" | head -c 200
echo ""
echo ""

echo "3. Exporting bundle..."
curl -s "$BASE/proof/$DEAL_ID" | python3 -m json.tool 2>/dev/null || curl -s "$BASE/proof/$DEAL_ID"
echo ""
echo ""

echo "=== Done ==="
echo "View: https://aigentsy.com/verify"
echo "Docs: https://aigentsy.com/quickstart"
