<?php

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

class CreateCommentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('topics', function (Blueprint $table) {
            $table->dropColumn('content');
            $table->dropColumn('url_id');
            $table->dropColumn('is_anonymous');
            $table->dropColumn('is_show_id');
            $table->dropColumn('is_published');
        });

        Schema::create('comments', function (Blueprint $table) {
            $table->id();
            $table->integer('topic_id');
            $table->integer('parent_id')->default(0);
            $table->text('content')->nullable();
            $table->string('image')->nullable();
            $table->integer('like')->default(0);
            $table->integer('dislike')->default(0);
            $table->string('author')->nullable();
            $table->smallInteger('is_anonymous')->default(1);
            $table->smallInteger('is_show_id')->default(0);
            $table->smallInteger('is_allow_comment')->default(1);
            $table->smallInteger('is_activated')->default(1);
            $table->smallInteger('is_deleted')->default(0);
            $table->timestamps();
        });

        Schema::create('comment_details', function (Blueprint $table) {
            $table->id();
            $table->integer('comment_id');
            $table->text('content')->nullable();
            $table->text('title')->nullable();
            $table->text('domain')->nullable();
            $table->text('description')->nullable();
            $table->string('thumbnail')->default('noimg@2x.png');
            $table->integer('current_img')->default(-1);
            $table->smallInteger('is_url')->default(0);
            $table->timestamps();
        });

        Schema::dropIfExists('urls');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('topics', function (Blueprint $table) {
            $table->text('content')->nullable();
            $table->integer('url_id')->nullable();
            $table->smallInteger('is_anonymous')->default(1);
            $table->smallInteger('is_show_id')->default(0);
            $table->smallInteger('is_published')->default(0);
        });

        Schema::dropIfExists('comments');
        Schema::dropIfExists('comment_details');

        Schema::create('urls', function (Blueprint $table) {
            $table->id();
            $table->integer('topic_id');
            $table->text('content')->nullable();
            $table->text('title')->nullable();
            $table->text('domain')->nullable();
            $table->text('description')->nullable();
            $table->string('thumbnail')->default('noimg@2x.png');
            $table->integer('current_img')->default(-1);
            $table->integer('image_id')->nullable();
            $table->smallInteger('is_url')->default(0);
            $table->timestamps();
        });
    }
}
