<?php

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

class CreateHostelTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::create('hostels', function (Blueprint $table) {

            $table->increments('id');
            $table->string('name')->nullable();
            $table->integer('owner_id')->nullable();

            $table->string('address')->nullable();
            $table->string('lat')->nullable();
            $table->string('lng')->nullbale();
            $table->string('province_id')->nullable();
            $table->string('district_id')->nullable();
            $table->string('ward_id')->nullable();

            $table->integer('number_rooms')->default(0);
            $table->integer('status')->default(0);
            $table->integer('status_confirm')->default(0);
            $table->integer('type')->default(0);

            $table->integer('electric_price')->default(0);
            $table->integer('water_price')->default(0);
            $table->integer('collaborator_id')->nullable();

            $table->text('desc')->nullable();

            $table->timestamps();
            $table->softDeletes();

        });

        Schema::create('rooms', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('floor')->default(1);
            $table->float('size')->default(0);
            $table->integer('type')->default(0);
            $table->integer('price')->default(0);
            $table->integer('deposit')->default(0);
            $table->integer('debt')->default(0);
            $table->integer('status')->default(0);

            $table->integer('current_electric')->default(0);
            $table->integer('current_water')->default(0);

            $table->string('current_renter')->nullable();
            $table->integer('hostel_id')->nullable();
            $table->text('desc')->nullable();

            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('amenities', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('icon')->nullable();
            $table->integer('status')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('hostel_amenities', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('hostel_id')->nullable();
            $table->integer('amenities_id')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });


        Schema::create('images', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('object_id')->nullable();
            $table->integer('object_type')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('collect_spends', function(Blueprint $table) {
            $table->increments('id');
            $table->integer('collect')->default(0);
            $table->integer('spend')->default(0);
            $table->integer('status')->default(0);
            $table->integer('type_action')->default(0);
            $table->integer('type')->default(0);
            $table->text('note')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('debts', function(Blueprint $table) {
            $table->increments('id');
            $table->integer('room_id')->nullable();
            $table->integer('amount')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('hostels');
        Schema::drop('rooms');
        Schema::drop('amenities');
        Schema::drop('hostel_amenities');
        Schema::drop('images');
        Schema::drop('collect_spends');
        Schema::drop('debts');
    }
}
