#!/usr/bin/env bash
# Smoke-test verification helper. Confirms the petdex-sourced sim is on the
# user's certified.one PDS and visible to the simocracy indexer.
set -euo pipefail

DID="did:plc:chek6tibulc4ujr4mishea5i"
PDS="https://certified.one"
INDEXER="https://simocracy-indexer-production.up.railway.app/graphql"

echo "1. Resolve PDS for the test account:"
curl -sS "https://plc.directory/$DID" | jq -r '.service[0].serviceEndpoint'
echo

echo "2. The sim record on the user's PDS:"
curl -sS "$PDS/xrpc/com.atproto.repo.listRecords?repo=$DID&collection=org.simocracy.sim" \
  | jq '.records[0].value | {name, spriteKind, petManifest, petSheetSize: .petSheet.size, petSheetMime: .petSheet.mimeType}'
echo

echo "3. Same record reported by the indexer:"
curl -sS "$INDEXER" -H 'Content-Type: application/json' \
  -d '{"query":"query Q($c:String!){records(collection:$c,first:1000){edges{node{uri did}}}}","variables":{"c":"org.simocracy.sim"}}' \
  | jq --arg did "$DID" '.data.records.edges | map(select(.node.did == $did)) | .[0].node.uri'
