<?php

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

class CreateAddressesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('addresses', function (Blueprint $table) {
            $table->id();
            $table->string('sap_nr', 18)->unique()->nullable();
            $table->unsignedBigInteger('shopify_id')->unique();
            $table->unsignedBigInteger('customer_id');

            $table->string('first_name', 255);
            $table->string('last_name', 255);
            $table->string('company', 255)->nullable();
            $table->string('address1', 255);
            $table->string('address2', 255)->nullable();
            $table->string('city', 255)->nullable();
            $table->string('province', 255)->nullable();
            $table->string('country', 255);
            $table->string('country_code', 6);
            $table->string('zip', 50);
            $table->string('phone', 50)->nullable();
            $table->boolean('is_default')->default(true);
            $table->string('note', 255)->nullable();

            $table->string('sync_hash')->nullable();
            $table->dateTime('last_sync_at')->nullable();
            $table->boolean('to_sync')->default(true);
            $table->timestamps();

            $table->foreign('customer_id')
                ->references('id')->on('customers')
                ->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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