#!/usr/bin/env bash
# Owner pacing snapshot
# Where each owner’s revenue sits against the same point last year. The report to paste into an owner update before they ask.
#
# Category : Revenue
# Safety   : read only
# Uses     : reports run
# Returns  : Per-owner pacing against the prior year, ready to paste.
#
# Requires the SendSquared CLI and jq:
#   curl -fsSL https://cli.sendsquared.com/install.sh | bash
#   sendsquared auth login
#
# Free to use and adapt. https://sendsquared.com/cli/scripts/#owner-pacing

# Owner pacing. This report takes a single as-of date, not a range.
set -euo pipefail
AS_OF=${1:-$(date -u +%F)}

R=$(sendsquared reports run owner_pacing --date "$AS_OF")
N=$(jq '[.data[]?] | length' <<<"$R")
if [ "$N" -eq 0 ]; then
  echo "no owner pacing rows as of $AS_OF (owner reporting may not be enabled on this account)"
  exit 0
fi
sendsquared reports run owner_pacing --date "$AS_OF" -o md
