#!/bin/bash
# Start amar room (managed app + soleprint)
#
# Usage:
#   ./start.sh              # Start all (foreground)
#   ./start.sh -d           # Start all (detached)
#   ./start.sh amar         # Start only amar
#   ./start.sh soleprint    # Start only soleprint
#   ./start.sh --build      # Rebuild images

set -e
cd "$(dirname "$0")/.."

BUILD=""
DETACH=""
TARGET="all"

for arg in "$@"; do
    case $arg in
        -d|--detached) DETACH="-d" ;;
        --build) BUILD="--build" ;;
        amar) TARGET="amar" ;;
        soleprint) TARGET="soleprint" ;;
    esac
done

if [ "$TARGET" = "all" ] || [ "$TARGET" = "amar" ]; then
    echo "Starting amar..."
    docker compose up $DETACH $BUILD
fi

if [ "$TARGET" = "all" ] || [ "$TARGET" = "soleprint" ]; then
    echo "Starting soleprint..."
    (cd soleprint && docker compose up $DETACH $BUILD)
fi

if [ -n "$DETACH" ]; then
    echo ""
    docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "(amar|soleprint|NAMES)"
fi
