<?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_infos', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('event_id');
            $table->string('type', 150)->nullable();
            $table->string('link')->nullable();
            $table->unsignedBigInteger('backend_user_id')->nullable();
            $table->nullableTimestamps();

            $table->foreign('event_id')->references('id')
                ->on('events')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');
        });

        Schema::create('event_info_languages', function (Blueprint $table): void {
            $table->bigIncrements('translation_id');
            $table->unsignedBigInteger('event_info_id');
            $table->string('language_id', 10);

            $table->string('title', 255);
            $table->string('content', 255)->nullable();

            // Languages
            $table->unique(['event_info_id', 'language_id'], 'idx_events_info_language');
            $table->foreign('event_info_id')
                ->references('id')
                ->on('event_infos')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
        });
    }

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