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

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

echo "==> API integration tests"
dotnet test VigilCareClinicalAPI.Tests --filter "FullyQualifiedName~OperationsApi"

echo "==> Vitest ops view"
cd vigilcare-dashboard && npm run test -- GatewayOperations.spec.js && cd ..

echo "==> Optional partition demo (skip with SKIP_PARTITION=1)"
if [[ "${SKIP_PARTITION:-0}" != "1" ]]; then
  export CENTRAL_URL="${CENTRAL_URL:-http://localhost:5270}"
  ./scripts/demo-network-partition.sh
fi

echo "==> Grafana checklist"
echo "  - Open http://localhost:3101 (admin/admin)"
echo "  - Dashboard: VigilCare Clinical"
echo "  - Verify panels: Ward Gateways Offline, Gateway Buffer Depth,"
echo "    Clinical Sync Batches, Total Sync Backlog"
echo "  - Export snapshot via Share → Snapshot"

echo "Phase 23 verification passed."