#!/usr/bin/env bash
# Print a call's analysis: summary, extracted fields and goal result. Needs: curl, jq.
set -euo pipefail
BASE="${RELATIONSAI_API_BASE:-https://voice-api.relationsai.com/v1}"
: "${CALL_ID:?Set CALL_ID to a call id (call_...)}"

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

jq -r '
  "state=\(.state) goal_met=\(.goal_met)",
  "summary (\(.summary.state)): \(.summary.text // "-")",
  (.extracted_fields[] | "  \(.name) [\(.type), \(.state)] = \(.value)")
' <<<"$analysis"
