<?php

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

class CreatePropertyWebTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create('property_web_template', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 128)->unique();
            $table->string('folder_name', 200);
            $table->tinyInteger('status')->default(1);
            $table->unsignedInteger('created_by');
            $table->unsignedInteger('updated_by');
            $table->integer('created_at');
            $table->integer('updated_at');

        });


        Schema::create('property_web', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('property_id')->unsigned();
            $table->string('domain', 50)->unique();
            $table->string('default_language', 10)->default('en_EN');
            $table->unsignedInteger('template_id')->default(1);
            $table->string('token',128)->unique();
            $table->tinyInteger('status')->default(1);
            $table->unsignedInteger('created_by');
            $table->unsignedInteger('updated_by');
            $table->integer('created_at');
            $table->integer('updated_at');

            $table->foreign('property_id')->references('id')->on('property');
            $table->foreign('template_id')->references('id')->on('property_web_template');

        });

        DB::table('property_web_template')->insert(
            [
                [
                    'name' => 'Default Template',
                    'folder_name' => 'default',
                    'status' => 1,
                    'created_by' => 1,
                    'updated_by' => 1,
                    'created_at' => 1,
                    'updated_at' => 1,
                ],
            ]
        );
    }

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