#!/usr/bin/env bash
# Local dev helper: start Postgres, then foreground the controller.
# Run the agent separately in another terminal: go run ./agent/cmd/agent --insecure
set -euo pipefail

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

echo ">> starting postgres"
docker compose -f docker-compose.dev.yml up -d postgres

echo ">> waiting for postgres to be healthy"
for _ in {1..30}; do
    if docker inspect -f '{{.State.Health.Status}}' panel-postgres 2>/dev/null | grep -q healthy; then
        echo ">> postgres healthy"
        break
    fi
    sleep 1
done

echo ">> running controller (Ctrl-C to stop)"
exec go run ./controller/cmd/controller "$@"
