<?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('employee_loans', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('employees')->onDelete('cascade');
            $table->decimal('total_amount',  12, 2)->default(0);   // total loan sanctioned
            $table->decimal('paid_amount',   12, 2)->default(0);   // recovered so far
            $table->decimal('monthly_deduction', 12, 2)->default(0); // fixed monthly cut
            $table->date('start_date');
            $table->date('end_date')->nullable();
            $table->enum('status', ['active','completed','cancelled'])->default('active');
            $table->text('notes')->nullable();
            $table->timestamps();
        });
    }

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