<?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 Teilnahmeoptionen je Anmeldung -- eine Zeile pro beantworteter Frage.
        // Frage-/Options-Label werden als Snapshot mitgespeichert, damit spätere Änderungen der
        // Fragen-Definition am Event bestehende Anmeldungen/Auswertungen nicht verfälschen.
        Schema::create('event_participant_options', 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('question_key');
            $table->string('question_label');
            $table->string('value');
            $table->string('value_label');

            $table->timestamps();

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

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