<?php

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

class CreateWishListsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up() :void
    {
        Schema::create('wish_lists', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id');
//            $table->json('tags'); // json-string
            $table->string('tags'); // json-string
            $table->string('caption');
            $table->unsignedInteger('subcategory_id')->nullable();
            $table->string('description')->default('');

            $table->foreign('user_id')
                ->references('id')->on('users')
                ->onDelete('cascade');
            $table->foreign('subcategory_id')
                ->references('id')->on('subcategories')
                ->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down() :void
    {
        Schema::table('wish_lists', function (Blueprint $table) {
            $table->dropForeign(['user_id']);
            $table->dropForeign(['subcategory_id']);
        });
        Schema::dropIfExists('wish_lists');
    }
}
