<?php

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

class CreateFooterAndLangTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('footer', function (Blueprint $table) {
            $table->bigIncrements('id');

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

            $table->json('legal_link_info');
            $table->json('email_contact');
            $table->json('phone_contact');

            $table->timestamps();
        });

        Schema::create('footer_languages', function (Blueprint $table) {
            $table->bigIncrements('translation_id');

            $table->unsignedBigInteger('footer_id');
            $table->string('language_id', 10);

            $table->string('title', 150);
            $table->string('address', 150);
            $table->string('copyright_text', 150);
            $table->string('funny_phrase', 25);

            $table->unique(['footer_id', 'language_id'], 'idx_footer_lang');
            $table->foreign('footer_id')
                ->references('id')
                ->on('footer')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('footer_languages');
        Schema::dropIfExists('footer');
    }
}
