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

msg="$1"
APPRISE_API_URL="${APPRISE_API_URL:-}"

# Local Apprise CLI if available
if command -v apprise >/dev/null 2>&1; then
  apprise -b "$msg" >/dev/null 2>&1 || true
fi

# Apprise API
if [[ -n "$APPRISE_API_URL" ]]; then
  curl -fsS -X POST -H "Content-Type: application/json" \
    -d "$(jq -n --arg b "$msg" '{body:$b}')" \
    "$APPRISE_API_URL/notify" >/dev/null 2>&1 || true
fi
