#!/bin/bash
set -euo pipefail

TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)

echo "=== NODE1 SNAPSHOT ==="
echo "timestamp_utc: $TS"

echo ""
echo "--- git (deployment checkout) ---"
if [ -d "/opt/microdao-daarion.repo/.git" ]; then
  cd /opt/microdao-daarion.repo
  echo "path: /opt/microdao-daarion.repo"
  echo "head: $(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
  echo "branch: $(git branch --show-current 2>/dev/null || echo 'detached')"
  echo "status:"
  git status -sb 2>/dev/null || true
else
  echo "WARN: /opt/microdao-daarion.repo not found"
fi

echo ""
echo "--- docker ps (top 30) ---"
docker ps --format "table {{.Names}}	{{.Status}}	{{.Image}}" | head -30

echo ""
echo "--- router/gateway/memory health ---"
for u in   "http://127.0.0.1:9102/health"   "http://127.0.0.1:9300/health"   "http://127.0.0.1:8000/health"   "http://127.0.0.1:6333/healthz" ; do
  code=$(curl -sS -m 3 -o /dev/null -w "%{http_code}" "$u" || true)
  echo "$u => $code"
done

echo ""
echo "--- docker inspect (router/gateway images) ---"
for c in dagi-router-node1 dagi-gateway-node1 dagi-memory-service-node1; do
  if docker inspect "$c" >/dev/null 2>&1; then
    img=$(docker inspect -f '{{.Config.Image}}' "$c" 2>/dev/null || true)
    prj=$(docker inspect -f '{{ index .Config.Labels "com.docker.compose.project" }}' "$c" 2>/dev/null || true)
    echo "$c image=$img compose_project=$prj"
  else
    echo "$c not_found"
  fi
done
