#!/bin/sh
# Triggers the leftover-expiry reminder send on the `web` service. Run on a
# schedule by busybox crond (see cron/crontab). Fails loudly (non-zero exit,
# stderr) but crond just tries again tomorrow — no retry loop here on purpose,
# keep this script trivial.
set -eu

: "${WEB_INTERNAL_URL:=http://web:3000}"

if [ -z "${CRON_SECRET:-}" ]; then
  echo "run-leftover-reminders: CRON_SECRET is not set, refusing to call the endpoint" >&2
  exit 1
fi

curl -fsS -X POST \
  -H "Authorization: Bearer ${CRON_SECRET}" \
  "${WEB_INTERNAL_URL}/api/internal/cron/leftover-reminders"
