#!/usr/bin/env bash
set -euo pipefail

# Kontrollskript fuer die ersten 24h nach Migration.

APP_DIR="${APP_DIR:-$(pwd)}"
DOMAIN_URL="${DOMAIN_URL:-https://hoerdle.de}"
CONTAINER_NAME="${CONTAINER_NAME:-hoerdle}"

cd "$APP_DIR"

echo "== Hördle Post-Migration Check =="
echo "App dir: $APP_DIR"
echo "Domain:  $DOMAIN_URL"
echo

echo "-- Container Status --"
docker compose ps
echo

echo "-- Health Endpoint --"
curl -fsS "$DOMAIN_URL/api/daily" >/dev/null
echo "OK: /api/daily erreichbar"
echo

echo "-- Fehlerlogs (24h) --"
docker compose logs --since=24h "$CONTAINER_NAME" 2>&1 | grep -Ei "(error|exception|fatal|panic)" || true
echo

echo "-- Backup Testlauf --"
./scripts/backup-persistence.sh
echo

echo "Postcheck abgeschlossen."
