<?php
 
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('loans', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->constrained()->onDelete('cascade');

            $table->integer('amount');          // 5000, 10000 etc
            $table->integer('tenure_months');   // 3, 6, 9, 12
            $table->string('purpose');          // business, study, etc

            $table->float('interest_rate')->default(5);  // 5%
            $table->integer('total_payable')->nullable();
            $table->integer('monthly_installment')->nullable();

            $table->string('status')->default('draft');
            // draft -> summary দেখানো পর্যন্ত
            // pending_deposit -> ডিপোজিট দেয়নি
            // pending_approval -> ডিপোজিট submit হয়েছে, admin approve করবে
            // running -> অনুমোদন হয়ে গেছে, কিস্তি চলছে
            // completed / rejected

            // NID file paths
            $table->string('nid_front_path')->nullable();
            $table->string('nid_back_path')->nullable();

            $table->timestamp('approved_at')->nullable();
            $table->timestamp('completed_at')->nullable();

            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('loans');
    }
};
