<?php

require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

use App\Models\Event;
use App\Models\EventOccurrence;

$count = Event::count();
$published = Event::where('status', 'published')->count();

echo "===== DATENBANKSTATUS =====" . PHP_EOL;
echo "Gesamt Events: " . $count . PHP_EOL;
echo "Published Events: " . $published . PHP_EOL;

if ($count > 0) {
    $event = Event::first();
    echo "\nErstes Event:\n";
    echo "- ID: " . $event->id . PHP_EOL;
    echo "- Title: " . $event->title . PHP_EOL;
    echo "- Status: " . $event->status . PHP_EOL;
    echo "- Category: " . ($event->category ?? "N/A") . PHP_EOL;
    echo "- Location: " . ($event->location ?? "N/A") . PHP_EOL;
    
    $occurrences = $event->occurrences()->count();
    echo "- Termine: " . $occurrences . PHP_EOL;
    
    if ($event->status !== 'published') {
        echo "\n⚠️  Event ist NICHT 'published'! Aktualisiere Status...\n";
        $event->update(['status' => 'published']);
        echo "✅ Status aktualisiert!\n";
    }
}

if ($published === 0 && $count > 0) {
    echo "\n⚠️  Keine Published-Events gefunden! Aktualisiere alle Events...\n";
    Event::query()->update(['status' => 'published']);
    echo "✅ Alle Events auf 'published' gesetzt!\n";
}

echo "\n✅ Setup abgeschlossen!\n";
