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

HEALTH_URL="https://billing.markedapp.com/api/health"

status="$(
  curl -fsS "$HEALTH_URL" | jq -r '.status // empty'
)"

if [[ "$status" == "ok" ]]; then
  terminal-widget \
    --target billingstatus \
    --icon checkmark.seal.fill \
    --background "#639992" \
    --foreground "#ffffff" \
    --text "Billing Server Healthy"
else
  terminal-widget \
    --target billingstatus \
    --icon xmark.seal.fill \
    --background "#ad343e" \
    --foreground "#ffffff" \
    --text "Billing Server Error"
fi