<?php

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

class CreateShoppingUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('shopping_users', function (Blueprint $table) {
            $table->increments('id');

            $table->unsignedInteger('auth_user_id')->nullable();
            $table->unsignedInteger('member_id')->nullable();

            $table->unsignedInteger('number')->index()->nullable();
            $table->boolean('is_like')->default(false);

            $table->char('billing_salutation', 2)->nullable();
            $table->string('billing_company')->nullable();
            $table->string('billing_firstname')->nullable();
            $table->string('billing_lastname')->nullable();
            $table->string('billing_address')->nullable();
            $table->string('billing_address_2')->nullable();
            $table->string('billing_zipcode')->nullable();
            $table->string('billing_city')->nullable();
            $table->unsignedInteger('billing_country_id');
            $table->string('billing_phone')->nullable();
            $table->string('billing_email')->nullable();
            $table->boolean('faker_mail')->default(false);
            $table->string('shipping_email')->nullable();

            $table->unsignedSmallInteger('orders')->nullable()->default(1);

            $table->boolean('accepted_data_checkbox')->default(false);

            $table->boolean('same_as_billing')->default(true);

            $table->char('shipping_salutation', 2)->nullable();
            $table->string('shipping_company')->nullable();
            $table->string('shipping_firstname')->nullable();
            $table->string('shipping_lastname')->nullable();
            $table->string('shipping_address')->nullable();
            $table->string('shipping_address_2')->nullable();
            $table->string('shipping_zipcode')->nullable();
            $table->string('shipping_city')->nullable();
            $table->unsignedInteger('shipping_country_id');
            $table->string('shipping_phone')->nullable();

            $table->boolean('abo_options')->default(false);
            $table->boolean('has_buyed')->default(false);
            $table->boolean('subscribed')->default(false);

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

            $table->char('mode', 4)->nullable();

            $table->char('is_for', 2)->nullable();
            $table->string('is_from', 10)->nullable();
            $table->unsignedInteger('shopping_user_id')->index()->nullable();


            $table->unsignedInteger('wp_order_number')->nullable();
            $table->timestamp('wp_order_date')->nullable();

            $table->timestamps();
            $table->softDeletes();
            $table->timestamp('user_deleted_at')->nullable();


            $table->foreign('billing_country_id')
                ->references('id')
                ->on('countries');

            $table->foreign('shipping_country_id')
                ->references('id')
                ->on('countries');

            $table->foreign('auth_user_id')
                ->references('id')
                ->on('users');

            $table->foreign('member_id')
                ->references('id')
                ->on('users');

        });
    }

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