<?php

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

class CreatePropertyTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('property', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',255);
            $table->unsignedInteger('destination_id')->nullable();
            $table->unsignedInteger('property_type_id')->nullable();
            $table->unsignedInteger('chain_id')->nullable();
            $table->double('rating')->nullable();
            $table->string('official_name',255)->nullable();
            $table->string('tax_office',255)->nullable();
            $table->string('tax_number',255)->nullable();
            $table->string('currency_type', 3)->nullable();
            $table->string('checkin_time', 50)->nullable();
            $table->string('checkout_time', 50)->nullable();
            $table->tinyInteger('status')->default(1)->index();
            $table->unsignedInteger('created_by');
            $table->unsignedInteger('updated_by');
            $table->integer('created_at');
            $table->integer('updated_at');
        });

        Schema::table('property', function (Blueprint $table) {

            $table->foreign('property_type_id')->references('id')->on('property_type');
            $table->foreign('chain_id')->references('id')->on('property_chain');
            $table->foreign('currency_type')->references('code')->on('currency');
            $table->foreign('created_by')->references('id')->on('user');
            $table->foreign('updated_by')->references('id')->on('user');
        });
    }

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