<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('accounts', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->unique();
            $table->string('account_number')->nullable();
            $table->string('account_type')->nullable();
            $table->string('account_currency')->nullable();
            $table->string('pin');
            $table->decimal('balance',19,4)->default(0);
            $table->decimal('previous_balance',19,4)->default(0);
            $table->dateTime('previous_balance_date')->default(now());
            $table->integer('otp')->nullable();
            $table->dateTime('otp_expiry')->nullable();
            $table->integer('tax_code')->nullable();
            $table->integer('imf_code')->nullable();
            $table->integer('cot_code')->nullable();
            $table->integer('current_transfer_count')->default(0)->comment('incase admin deletes transaction history for user, keeps track of numbers of transfers made');
            $table->integer('max_transfer_count')->nullable()->comment('maximum amount of times user can make transfer');
            $table->decimal('max_transfer_amount',19,4)->nullable()->comment('maximum amount of fund user can transfer before being asked to upgrade account');
            $table->boolean('made_first_transfer')->default(false);
            $table->timestamps();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

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