#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

echo "=== ScadaBridge Docker Deploy ==="

# Build image (creates network if needed)
"$SCRIPT_DIR/build.sh"

echo ""
echo "Deploying containers..."
docker compose -f "$SCRIPT_DIR/docker-compose.yml" up -d --force-recreate

echo ""
echo "Container status:"
docker compose -f "$SCRIPT_DIR/docker-compose.yml" ps

echo ""
echo "Access points:"
echo "  Central (Traefik LB): http://localhost:9000"
echo "  Central UI (node A):  http://localhost:9001"
echo "  Central UI (node B):  http://localhost:9002"
echo "  Health check:         http://localhost:9001/health/ready"
echo "  Active node check:    http://localhost:9001/health/active"
echo "  Traefik dashboard:    http://localhost:8180"
echo "  Management API:       http://localhost:9000/management"
echo ""
echo "To seed test sites (first-time setup):"
echo "  docker/seed-sites.sh"
echo ""
echo "Logs: docker compose -f $SCRIPT_DIR/docker-compose.yml logs -f"
