<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('loans', function (Blueprint $table) {
            $table->id();
            $table->foreignId('borrower_id')->constrained('borrowers')->onDelete('cascade');
            $table->string('code', 15)->nullable();
            $table->string('type', 10); // MZ/HZ
            $table->decimal('amount', 15, 2);
            $table->date('date');
            $table->date('due_date');
            $table->string('attachment')->nullable();
            $table->boolean('is_valid')->default(0);
            $table->datetime('validation_date')->nullable();
            $table->decimal('total_restitutions', 15, 2)->default(0);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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