<?php

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

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

            $table->unsignedInteger('m_account')->unique()->nullable();
            $table->char('m_salutation', 2)->nullable();
            $table->string('m_first_name')->nullable();
            $table->string('m_last_name')->nullable();
            $table->text('m_notes')->nullable();


            $table->string('company')->nullable();
            $table->char('salutation', 2)->nullable();
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('address')->nullable();
            $table->string('address_2')->nullable();
            $table->string('zipcode', 10)->nullable();
            $table->string('city')->nullable();

            $table->unsignedInteger('country_id')->index()->default(1);

            $table->unsignedInteger('pre_phone_id')->nullable();
            $table->string('phone')->nullable();
            $table->unsignedInteger('pre_mobil_id')->nullable();
            $table->string('mobil')->nullable();

            $table->string('tax_number', 20)->nullable();
            $table->string('tax_identification_number', 20)->nullable();
            $table->unsignedTinyInteger('taxable_sales')->nullable();

            $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')->default(1);

            $table->unsignedInteger('shipping_pre_phone_id')->nullable();
            $table->string('shipping_phone')->nullable();

            $table->date('birthday')->nullable();
            $table->string('website')->nullable();
            $table->string('facebook')->nullable();
            $table->string('facebook_fanpage')->nullable();
            $table->string('instagram')->nullable();

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

            $table->timestamp('data_protection')->nullable();
            $table->timestamp('accepted_contract')->nullable();
            $table->text('notice')->nullable();

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


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

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

        });
    }

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