<?php

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

class CreateWalletTransactionTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('wallet_transaction', function (Blueprint $table) {
            $table->id();

            $table->foreignId('wallet_id')->unsigned();
            $table->foreignId('transaction_id')->unsigned()->nullable();
            $table->foreignId('bill_no')->unsigned();
            $table->integer('type')->default(TransactionType::PAYMENT);
            $table->decimal('amount', 14, 5)->default(0.00);
            $table->foreignId('currency_id')->unsigned();
            $table->decimal('original_amount', 14, 5)->default(0.00);
            $table->foreignId('original_currency_id')->unsigned();
            $table->decimal('currency_rate', 14, 5)->default(0.00);
            $table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION);
            $table->softDeletes();
            $table->timestamps();

            $table->foreign('transaction_id')->references('id')->on('transactions');
            $table->foreign('wallet_id')->references('id')->on('wallets');
            $table->foreign('currency_id')->references('id')->on('currencies');
            $table->foreign('original_currency_id')->references('id')->on('currencies');
            
        });
    }

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