<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('payment_delays', function (Blueprint $table) {
            $table->id();
            $table->foreignId('customer_id')->constrained()->onDelete('cascade');
            $table->foreignId('rental_id')->constrained('rentals')->onDelete('cascade');
            $table->decimal('original_amount', 12, 2);
            $table->decimal('delayed_amount', 12, 2);
            $table->date('due_date');
            $table->date('actual_payment_date')->nullable();
            $table->integer('delay_days')->default(0);
            $table->decimal('late_fee', 12, 2)->default(0);
            $table->enum('status', ['pending', 'overdue', 'paid', 'written_off'])->default('pending');
            $table->text('notes')->nullable();
            $table->foreignId('created_by')->constrained('users')->onDelete('restrict');
            $table->timestamps();
            $table->index('customer_id');
            $table->index('rental_id');
            $table->index('status');
            $table->index('due_date');
        });
    }

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