#!/usr/bin/env bash
# Check that an agent can place calls. Exits 1 when it is not ready. Needs: curl, jq.
set -euo pipefail
BASE="${RELATIONSAI_API_BASE:-https://voice-api.relationsai.com/v1}"
AGENT_ID="${AGENT_ID:-agent_1ZltiWzxrXmMprGD6q63}" # the test-mode Sample agent unless you set your own

readiness=$(curl -sS --fail-with-body "$BASE/agents/$AGENT_ID/readiness" \
  -H "Authorization: Bearer $RELATIONSAI_API_KEY") || { echo "$readiness" >&2; exit 1; }

if [ "$(jq -r '.ready' <<<"$readiness")" = "true" ]; then
  echo "$AGENT_ID is ready to place calls"
else
  echo "$AGENT_ID is not ready:"
  jq -r '.reasons[] | "  \(.code): \(.message)"' <<<"$readiness"
  exit 1
fi
