#!/bin/bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
REGISTRY="$ROOT_DIR/.smbatcher/REGISTRY.md"
TRACKERS="$ROOT_DIR/.smbatcher/batches"

if [[ ! -f "$REGISTRY" ]]; then
  echo "ERROR:registry_not_found:$REGISTRY"
  exit 2
fi

echo "Registry:"
grep "|" "$REGISTRY" | tail -n +2

echo ""
echo "Batch trackers:"
ls "$TRACKERS" 2>/dev/null | grep -E '^batch-.*\.md$' || echo "(none)"

echo ""
REG_COUNT=$(grep -c "^|" "$REGISTRY" 2>/dev/null || echo "0")
TRACKER_COUNT=$(ls "$TRACKERS" 2>/dev/null | grep -cE '^batch-.*\.md$' || echo "0")
echo "OK:status_report:$REG_COUNT registry entries, $TRACKER_COUNT batch trackers"
