<?php

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

return new class extends Migration {
    public function up(): void
    {
        // Gewählte Zusätze je Anmeldung -- eine Zeile pro gebuchtem Addon.
        // Titel/Preis/Betrag werden als Snapshot mitgespeichert (relevant für die spätere Rechnung).
        Schema::create('event_participant_addons', function (Blueprint $table) {
            $table->id();
            $table->string('tenant');

            $table->foreignId('event_id')->constrained('events', 'id')->cascadeOnDelete()->cascadeOnUpdate();
            $table->foreignId('event_participant_id')->constrained('event_participants', 'id')->cascadeOnDelete()->cascadeOnUpdate();

            $table->string('addon_key');
            $table->string('title');
            $table->float('price')->default(0);
            $table->boolean('flat')->default(false);
            $table->integer('days')->default(0);
            $table->float('amount')->default(0);

            $table->timestamps();

            $table->foreign('tenant')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('event_participant_addons');
    }
};
