<?php

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

class CreateStatementTransactionOwnersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('statement_transaction_owners', function (Blueprint $table) {
            $table->id();
            $table->foreignId('statement_transaction_id');
            $table->integer('type')->default(StatementTransactionOwnerType::UNKNOWN);
            $table->string('system')->nullable();
            $table->string('owner_type')->nullable();
            $table->bigInteger('owner_id')->nullable();
            $table->string('owner_reference')->nullable();
            $table->string('invoice_reference')->nullable();
            $table->string('receipt_reference')->nullable();
            $table->string('is_auto_mapped')->default(false);
            $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION);

            $table->foreign('statement_transaction_id')->references('id')->on('statement_transactions');
            $table->timestamps();
        });
    }

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