<?php

use App\Classes\ValueObjects\Constants\AddressType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
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->morphs('owner');
            $table->string('reference')->nullable();
            $table->string('street_one');
            $table->string('street_two')->nullable();
            $table->foreignId('district_id');
            $table->foreignId('state_id');
            $table->foreignId('country_id');
            $table->string('postcode', '45');
            $table->integer('type')->default(AddressType::DELIVERY);
            $table->integer('default')->default(false);
            $table->integer('status')->default(ApprovalStatus::APPROVED);
            $table->softDeletes();
            $table->timestamps();
        });

        Schema::table('addresses', function (Blueprint $table) {
            $table->string('owner_type', 191)->change();
        });
    }

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