#!/bin/bash
# Quick status check script for IGNY8 stacks and containers

echo "╔════════════════════════════════════════════════════════════════════════════╗"
echo "║                  IGNY8 STACK & CONTAINER STATUS REPORT                     ║"
echo "╚════════════════════════════════════════════════════════════════════════════╝"
echo ""

echo "📦 APP STACK (igny8-app):"
docker ps --filter "label=com.docker.compose.project=igny8-app" --format "   ✅ {{.Names}} | Status: {{.Status}} | Ports: {{.Ports}}"
if [ $? -ne 0 ] || [ -z "$(docker ps --filter 'label=com.docker.compose.project=igny8-app' --format '{{.Names}}')" ]; then
    echo "   ⚠️  No app stack containers found"
fi

echo ""
echo "🏗️  INFRA STACK (igny8-infra):"
docker ps --filter "label=com.docker.compose.project=igny8-infra" --format "   ✅ {{.Names}} | Status: {{.Status}}"
if [ $? -ne 0 ] || [ -z "$(docker ps --filter 'label=com.docker.compose.project=igny8-infra' --format '{{.Names}}')" ]; then
    echo "   ⚠️  No infra stack containers found"
fi

echo ""
echo "🌐 NETWORK CONNECTIVITY (igny8_net):"
CONTAINER_COUNT=$(docker network inspect igny8_net --format '{{len .Containers}}' 2>/dev/null || echo "0")
echo "   Connected: $CONTAINER_COUNT containers"

echo ""
echo "🔍 SERVICE HEALTH CHECKS:"
BACKEND_CODE=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8011/api/v1/plans/ 2>/dev/null || echo "000")
FRONTEND_CODE=$(curl -s -o /dev/null -w '%{http_code}' http://localhost:8021/ 2>/dev/null || echo "000")
POSTGRES_HEALTH=$(docker exec igny8_postgres pg_isready -U igny8 2>&1 | grep -q 'accepting' && echo "healthy" || echo "unhealthy")
REDIS_HEALTH=$(docker exec igny8_redis redis-cli ping 2>&1 | grep -q PONG && echo "healthy" || echo "unhealthy")

echo "   Backend API:   $BACKEND_CODE $([ "$BACKEND_CODE" = "200" ] && echo "✅" || echo "❌")"
echo "   Frontend:      $FRONTEND_CODE $([ "$FRONTEND_CODE" = "200" ] && echo "✅" || echo "❌")"
echo "   Postgres:      $POSTGRES_HEALTH $([ "$POSTGRES_HEALTH" = "healthy" ] && echo "✅" || echo "❌")"
echo "   Redis:         $REDIS_HEALTH $([ "$REDIS_HEALTH" = "healthy" ] && echo "✅" || echo "❌")"

echo ""
echo "📋 ALL IGNY8 CONTAINERS:"
docker ps --filter "name=igny8" --format "   {{.Names}} | {{.Image}} | {{.Status}}"

echo ""
echo "════════════════════════════════════════════════════════════════════════════"

