<?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('executing_party_group_companies', function (Blueprint $table) {
            $table->bigIncrements('id');

            $table->unsignedBigInteger('executing_party_group_id');
            $table->foreign('executing_party_group_id')->references('id')
                ->on('executing_party_groups')->onDelete('CASCADE')->onUpdate('CASCADE');

            $table->unsignedBigInteger('backend_user_id')->nullable();
            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');

            $table->unsignedBigInteger('account_id')->nullable();
            $table->foreign('account_id')->references('id')
                ->on('accounts')->onDelete('SET NULL')->onUpdate('CASCADE');

            $table->nullableTimestamps();
        });

        Schema::create('executing_party_group_company_languages', function (Blueprint $table) {
            $table->bigIncrements('translation_id');
            $table->unsignedBigInteger('executing_party_group_company_id');
            $table->string('language_id', 10);
            $table->string('title', 150);

            $table->unique(['executing_party_group_company_id', 'language_id'], 'idx_executing_party_group_company_language');
            $table->foreign('executing_party_group_company_id', 'executing_party_group_company_id_fk')
                ->references('id')
                ->on('executing_party_group_companies')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
        });
    }

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