#!/bin/bash
#
# Crumbforest Logs Script
# Zeigt Logs verschiedener Services
#

echo "🦉 Crumbforest Logs"
echo ""

cd compose

# Check if containers are running
if ! docker compose ps | grep -q "Up"; then
    echo "✗ Keine Container laufen"
    echo "  Starte sie mit: ./start.sh"
    exit 1
fi

# Service selection
if [ -z "$1" ]; then
    echo "Welche Logs möchtest du sehen?"
    echo ""
    echo "Services:"
    docker compose ps --format "table {{.Service}}\t{{.Status}}"
    echo ""
    echo "Beispiele:"
    echo "  ./logs.sh app         - FastAPI Logs"
    echo "  ./logs.sh db          - MariaDB Logs"
    echo "  ./logs.sh qdrant      - Qdrant Logs"
    echo "  ./logs.sh all         - Alle Logs"
    echo "  ./logs.sh app -f      - FastAPI Logs (follow)"
    echo ""
    read -p "Service: " service
else
    service=$1
fi

# Follow mode
follow=""
if [ "$2" = "-f" ] || [ "$2" = "--follow" ]; then
    follow="-f"
fi

echo ""

# Show logs
case $service in
    all)
        echo "=== Alle Logs ==="
        docker compose logs $follow
        ;;
    app|fastapi)
        echo "=== FastAPI Logs ==="
        docker compose logs $follow app
        ;;
    db|mariadb|mysql)
        echo "=== MariaDB Logs ==="
        docker compose logs $follow db
        ;;
    qdrant)
        echo "=== Qdrant Logs ==="
        docker compose logs $follow qdrant
        ;;
    nginx)
        echo "=== Nginx Logs ==="
        docker compose logs $follow nginx
        ;;
    *)
        echo "=== $service Logs ==="
        docker compose logs $follow $service
        ;;
esac
