#!/bin/bash
# admin-payments.sh -- Payments Monitor
TOOL_NAME="admin-payments"; TOOL_VERSION="2.0.0"; TOOL_TIER=2; TOOL_BIRD="swan"
TOOL_LOG="/opt/binary/logs/tools/${TOOL_NAME}.log"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ -f "${SCRIPT_DIR}/common.sh" ]]; then source "${SCRIPT_DIR}/common.sh"
elif [[ -f "${SCRIPT_DIR}/../common.sh" ]]; then source "${SCRIPT_DIR}/../common.sh"
else echo "FATAL: common.sh not found" >&2; exit 1; fi
export BIRD_ID="${TOOL_BIRD}"

_do_send_impl() { echo "=== Payments: ${NODE_ID} ==="; echo "  Status: monitoring via dashboard API"; tool_audit "send" "node=${NODE_ID}"; }
_do_status_impl() { echo "{\"tool\":\"${TOOL_NAME}\",\"node\":\"${NODE_ID}\",\"status\":\"healthy\",\"checked_at\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}"; }
_do_digest_impl() { _do_send_impl; }
_do_flush_impl() { [ -f "$TOOL_LOG" ] && truncate -s 0 "$TOOL_LOG"; }
tool_help() { echo "${TOOL_NAME} v${TOOL_VERSION} -- Payments Monitor"; }
do_send()   { tool_wrap "send"   _do_send_impl "$@"; }
do_status() { tool_wrap "status" _do_status_impl "$@"; }
do_digest() { tool_wrap "digest" _do_digest_impl "$@"; }
do_flush()  { tool_wrap "flush"  _do_flush_impl "$@"; }
tool_init; trap 'tool_complete' EXIT
case "${1:---help}" in --send) shift; do_send "$@" ;; --status) shift; do_status "$@" ;; --digest) shift; do_digest "$@" ;; --flush) shift; do_flush "$@" ;; --help) tool_help ;; *) handle_standard_command "$@" ;; esac
