<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('event_occurrences', function (Blueprint $table) {
            $table->id();
            $table->foreignId('event_id')->constrained('events')->cascadeOnDelete();
            $table->dateTime('start_datetime');
            $table->dateTime('end_datetime')->nullable();
            $table->boolean('is_all_day')->default(false);
            $table->string('location_details')->nullable(); // z.B. "Saal A", "Haupteingang"
            $table->integer('capacity')->nullable(); // Kapazität
            $table->integer('available_tickets')->nullable(); // Verfügbare Tickets
            $table->decimal('price', 10, 2)->nullable();
            $table->enum('status', ['scheduled', 'cancelled', 'completed'])->default('scheduled');
            $table->timestamps();

            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';

            // Indizes für Filter-Abfragen
            $table->index('event_id');
            $table->index('start_datetime');
            $table->index(['start_datetime', 'status']); // Composite Index für "nächste Events"
            $table->index(['event_id', 'status']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('event_occurrences');
    }
};
