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

: "${FORAGENT_BASE_URL:=https://foragent.io}"

check() {
  local path="$1"
  printf 'Checking %s\n' "$path"
  curl --fail -sS -o /dev/null "$FORAGENT_BASE_URL$path"
}

check /status.json
check /docs
check /starter/foragent-relay-contract.json
check /starter/foragent-openapi.json
check /starter/foragent-publication-manifest.json
check /starter/foragent-sdk.ts
check /starter/foragent-starter-app.ts
check /starter/foragent-starter-readme.md
check /starter/foragent-diagnostics.sh
check /starter/foragent-relay-smoke.sh

if [[ -n "${FORAGENT_PUBLIC_SLUG:-}" ]]; then
  check "/api/v1/agents/$FORAGENT_PUBLIC_SLUG/card"
  check "/a/$FORAGENT_PUBLIC_SLUG"
fi

printf '\nPublication diagnostics succeeded.\n'
