<?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('efz_status', function (Blueprint $table) {
            $table->string('slug')->primary();
            $table->string('name');
            $table->timestamps();
        });


        Schema::create('event_participants', function (Blueprint $table) {
            $table->id();
            $table->string('tenant');

            $table->foreignId('event_id')->constrained('events', 'id')->cascadeOnDelete()->cascadeOnUpdate();
            $table->foreignId('user_id')->nullable()->constrained('users', 'id')->cascadeOnDelete()->cascadeOnUpdate();
            $table->string('identifier')->unique();
            $table->string('firstname');
            $table->string('lastname');
            $table->string('nickname')->nullable();
            $table->string('participation_type');
            $table->string('local_group')->nullable();
            $table->date('birthday');
            $table->string('address_1');
            $table->string('address_2')->nullable();
            $table->string('postcode');
            $table->string('city');
            $table->string('email_1');
            $table->string('phone_1');
            $table->string('email_2')->nullable();
            $table->string('phone_2')->nullable();
            $table->string('contact_person')->nullable();
            $table->string('allergies')->nullable();
            $table->string('intolerances')->nullable();
            $table->string('medications')->nullable();
            $table->date('tetanus_vaccination')->nullable();
            $table->string('eating_habit')->nullable();
            $table->string('swimming_permission')->nullable();
            $table->string('first_aid_permission')->nullable();
            $table->boolean('foto_socialmedia')->default(false);
            $table->boolean('foto_print')->default(false);
            $table->boolean('foto_webseite')->default(false);
            $table->boolean('foto_partner')->default(false);
            $table->boolean('foto_intern')->default(false);
            $table->date('arrival_date');
            $table->date('departure_date');
            $table->integer('arrival_eating');
            $table->integer('departure_eating');
            $table->longText('notes')->nullable();
            $table->float('amount', 2);
            $table->float('amount_paid',0)->default(0);
            $table->string('payment_purpose');
            $table->string('efz_status');
            $table->timestamps();
            $table->dateTime('unregistered_at')->nullable();

            $table->foreign('swimming_permission')->references('slug')->on('swimming_permissions')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('eating_habit')->references('slug')->on('eating_habits')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('first_aid_permission')->references('slug')->on('first_aid_permissions')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('tenant')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('local_group')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('participation_type')->references('slug')->on('participation_types')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('efz_status')->references('slug')->on('efz_status')->restrictOnDelete()->cascadeOnUpdate();

        });

    }







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