#!/bin/bash
# Stop room services
#
# Usage:
#   ./stop.sh              # Stop all
#   ./stop.sh <service>    # Stop specific service
#
# This is a TEMPLATE. Copy to your room's ctrl/ and customize.

set -e

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

TARGET="all"
SERVICE_DIRS=()

# Auto-detect services
for dir in */; do
    [ -f "$dir/docker-compose.yml" ] && SERVICE_DIRS+=("${dir%/}")
done

[ -n "$1" ] && [[ " ${SERVICE_DIRS[*]} " =~ " $1 " ]] && TARGET="$1"

stop_service() {
    local svc=$1
    echo "Stopping $svc..."
    (cd "$svc" && docker compose down)
}

if [ "$TARGET" = "all" ]; then
    for svc in "${SERVICE_DIRS[@]}"; do
        stop_service "$svc"
    done
else
    stop_service "$TARGET"
fi

echo "Done."
