<?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('loan_installments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('loan_id')->constrained('loans')->onDelete('cascade');

            $table->date('due_date');
            $table->integer('amount');          // প্রতি মাসে দিতে হবে
            $table->integer('principal_part');  // চাইলে break down
            $table->integer('interest_part');

            // payment info
            $table->string('payment_method')->nullable();  // nagad, bkash, rocket
            $table->string('payment_trx_id')->nullable();  // SMS trx id
            $table->integer('paid_amount')->nullable();    // কত টাকা দিয়েছে

            $table->string('status')->default('upcoming'); // upcoming, paid, late
            $table->timestamp('paid_at')->nullable();

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

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