<?php

use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDocumentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('documents', function (Blueprint $table) {
            $table->id();
            $table->morphs('owner');
            $table->string('document_type');
            $table->string('reference');
            $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION);
            $table->timestamp('issued_date')->nullable();
            $table->timestamp('expired_date')->nullable();
            $table->foreignId('approver')->nullable()->unsigned();
            $table->timestamp('approval_date')->nullable();
            $table->softDeletes();
            $table->timestamps();

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

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