#!/usr/bin/env bash
# Jarvis AI Market — validate then list your x402 endpoint
# Listing fee: 0.10 USDC / 30d on HTTP 402 (PAYMENT-REQUIRED)
# Sales settle to YOUR sellerPayTo. No escrow. No keys on the market.
set -euo pipefail
BASE="${BASE:-https://x402-research.kgy5612.workers.dev}"
BODY='{"resource":"https://example.workers.dev/paid","method":"POST","priceUsdc":"0.03","description":"What a buyer agent receives after paying your endpoint.","sellerPayTo":"0x66890857dc33D5066c28AadBeb7CD078F50799A3","network":"eip155:8453"}'

echo "== schema =="
curl -sS "$BASE/listings/schema"; echo

echo "== dry-run validate (free) =="
curl -sS -X POST "$BASE/listings/validate" -H 'content-type: application/json' -d "$BODY"; echo

echo "== unpaid POST /listings (expect 402 + PAYMENT-REQUIRED) =="
curl -sS -D - -o /tmp/jarvis-listings-body.json -X POST "$BASE/listings" \
  -H 'content-type: application/json' -d "$BODY" | head -40
echo "(body often empty {}; decode PAYMENT-REQUIRED or GET $BASE/listings/challenge)"

echo "== next =="
echo "1) Sign PAYMENT-SIGNATURE for 0.10 USDC Exact on Base (eip155:8453)"
echo "2) Retry POST $BASE/listings with header PAYMENT-SIGNATURE"
echo "3) Confirm in GET $BASE/bazaar.json sellerListings"
