<?php

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

class CreateTransactionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('payee')->nullable();
            $table->bigInteger('payer')->nullable();
            $table->foreignId('purpose')->references('id')->on('purpose_heads')->onDelete('cascade');
            $table->bigInteger('amount');
            $table->enum('status', ['debit', 'credit']);
            $table->foreignId('processor')->references('id')->on('users')->onDelete('cascade');
            $table->string('model')->nullable();
            $table->string('payer_payee_model')->nullable();
            $table->foreignId('gateway')->references('id')->on('payment_gateways')->onDelete('cascade');
            $table->timestamps();
        });
    }

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