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

cd "$(dirname "$0")/.."

ATHENA_URL="${ATHENA_URL:-http://localhost:3001}"

request_url() {
  local url="$1"
  if command -v curl >/dev/null 2>&1; then
    curl -fsS "$url" >/dev/null
  else
    python3 -c "import urllib.request; urllib.request.urlopen('${url}', timeout=10).read()"
  fi
}

echo "==> Checking docker compose services"
docker compose ps

echo "==> Checking Hermes health endpoint inside Docker network"
docker compose exec -T hermes python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=10).read()"

echo "==> Checking Athena at ${ATHENA_URL}"
request_url "${ATHENA_URL}"

echo "==> Healthcheck completed"
