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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/common.sh"

echo "================================================================"
echo " dev-prom-e2e up"
echo "================================================================"

render_prometheus_config

echo "[dev-prom-e2e] starting docker-compose services..."
compose up -d

if ! wait_http "http://127.0.0.1:${DEV_PROM_E2E_PROMETHEUS_PORT}/-/healthy" 60; then
  echo "❌ Prometheus container did not become healthy"
  exit 1
fi

if ! wait_http "http://127.0.0.1:${DEV_PROM_E2E_GRAFANA_PORT}/api/health" 60; then
  echo "❌ Grafana container did not become healthy"
  exit 1
fi

echo "[dev-prom-e2e] waiting 25s for the first scrape..."
sleep 25

echo ""
echo "✅ dev-prom-e2e stack is up"
echo "Prometheus: http://127.0.0.1:${DEV_PROM_E2E_PROMETHEUS_PORT}"
echo "Grafana:    http://127.0.0.1:${DEV_PROM_E2E_GRAFANA_PORT}  (admin/admin)"
