<?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(): void
    {
        Schema::create('loans', function (Blueprint $table) {
           $table->id();
            $table->unsignedBigInteger('customer_id');
            // $table->string('loan_no')->unique();
            $table->decimal('loan_amount', 12, 2);
            $table->decimal('interest_rate', 5, 2);
            $table->enum('installment_type', ['daily', 'weekly', 'monthly']);
            $table->integer('installment_count');
            $table->decimal('total_interest', 12, 2);
            $table->decimal('total_payable', 12, 2);
            $table->decimal('installment_amount', 12, 2);
            $table->date('issue_date');
            $table->date('first_installment_date');
            $table->date('last_installment_date');
            $table->enum('status', ['pending', 'completed', 'cancelled', 'overdue','accept'])->default('pending');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->timestamps();

            // Optional foreign key
            // $table->foreign('customer_id')->references('id')->on('customers');
        });
    }

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