<?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')->nullable();
            $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION);
            $table->bigInteger('approved_by')->unsigned()->nullable();
            $table->timestamp('issued_date')->nullable();
            $table->timestamp('expired_date')->nullable();
            $table->timestamp('approved_date')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->foreign('approved_by')->references('id')->on('users')->onDelete('cascade');
        });
    }

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