#!/bin/bash
# View amar room logs
#
# Usage:
#   ./logs.sh              # All logs (tail)
#   ./logs.sh -f           # Follow mode
#   ./logs.sh backend      # Specific container
#   ./logs.sh soleprint    # Soleprint logs

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

FOLLOW=""
TARGET=""

for arg in "$@"; do
    case $arg in
        -f|--follow) FOLLOW="-f" ;;
        *) TARGET="$arg" ;;
    esac
done

if [ -z "$TARGET" ]; then
    echo "=== Amar ==="
    docker compose logs --tail=20 $FOLLOW
    echo ""
    echo "=== Soleprint ==="
    (cd soleprint && docker compose logs --tail=20 $FOLLOW)
elif [ "$TARGET" = "soleprint" ]; then
    (cd soleprint && docker compose logs $FOLLOW)
else
    docker logs $FOLLOW "amar_$TARGET" 2>/dev/null || docker logs $FOLLOW "$TARGET"
fi
