#!/bin/bash
# Healthcheck for Vikunja (app + database)

# Vikunja app container must be running
if ! docker ps --filter "name=vikunja" --filter "status=running" | grep -qw "vikunja"; then
    echo "[FAIL] vikunja container is not running"
    exit 1
fi

# Postgres container must be running
if ! docker ps --filter "name=vikunja-db" --filter "status=running" | grep -qw "vikunja-db"; then
    echo "[FAIL] vikunja-db container is not running"
    exit 1
fi

# API must respond
if ! curl -sf http://localhost:3456/api/v1/info > /dev/null; then
    echo "[FAIL] Vikunja API is not responding on :3456"
    exit 1
fi

echo "[OK] Vikunja is healthy"
exit 0
