<?php

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

class CreateGalleryItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('gallery_items', function (Blueprint $table) {
            $table->id();
            $table->string('uid')->unique();
            $table->bigInteger('gallery_id')->unsigned();
            $table->bigInteger('gallery_section_id')->unsigned();
            $table->string('type', 20);
            $table->bigInteger('image_item_id')->unsigned()->nullable();
            $table->bigInteger('child_gallery_id')->unsigned()->nullable();
            $table->string('status', 20)->nullable();
            $table->smallInteger('columns')->nullable();
            $table->boolean('is_recommended')->default(false);
            $table->integer('position');

            $table->timestamps();

            $table->foreign('gallery_id')
                ->references('id')
                ->on('galleries')
                ->onDelete('cascade');

            $table->foreign('gallery_section_id')
                ->references('id')
                ->on('gallery_sections')
                ->onDelete('cascade');

            $table->foreign('image_item_id')
                ->references('id')
                ->on('image_items')
                ->onDelete('cascade');

            $table->foreign('child_gallery_id')
                ->references('id')
                ->on('galleries')
                ->onDelete('cascade');
        });
    }

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