#!/bin/bash
set -euo pipefail

POSTGRES_CONTAINER="${POSTGRES_CONTAINER:-zgz_postgres}"
DIRECTUS_HEALTH_URL="${DIRECTUS_HEALTH_URL:-http://127.0.0.1:8056/server/health}"
DB_NAME="${DB_NAME:-zgz_turismo}"
DB_USER="${DB_USER:-directus}"

if ! command -v docker >/dev/null 2>&1; then
  echo "docker is not installed or not in PATH"
  exit 1
fi

echo "Directus health:"
curl -fsS "$DIRECTUS_HEALTH_URL"
echo ""

echo "Core collection counts:"
docker exec -i "$POSTGRES_CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" <<'SQL'
\pset pager off
select 'languages' as collection, count(*) from languages
union all
select 'ui_translations', count(*) from ui_translations
union all
select 'pois', count(*) from pois
union all
select 'pois_translations', count(*) from pois_translations
union all
select 'hotspots', count(*) from hotspots
union all
select 'routes', count(*) from routes
union all
select 'routes_translations', count(*) from routes_translations
union all
select 'homepage_slides', count(*) from homepage_slides;
SQL

echo ""
echo "Languages:"
docker exec -i "$POSTGRES_CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" -c "select code, name from languages order by code;"
