#!/bin/bash
set -euo pipefail

# scripts/lab/stop_all_services.sh

GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo -e "${YELLOW}🛑 Stopping all services...${NC}"

# Helper to kill process on port
kill_port() {
    local port=$1
    local name=$2
    local pid=$(lsof -t -i:$port || true)
    if [ -n "$pid" ]; then
        echo -e "Killing $name on port $port (PID: $pid)..."
        kill -9 $pid || true
    else
        echo -e "$name on port $port is not running."
    fi
}

kill_port 8080 "veza-backend-api"
kill_port 8081 "veza-chat-server"
kill_port 8082 "veza-stream-server"
kill_port 3000 "apps/web"

echo -e "${GREEN}✅ All services stopped.${NC}"
