<?php

use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
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('tuition_payments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('invoice_id')->constrained('tuition_invoices')->cascadeOnDelete();
            $table->decimal('amount_paid', 15, 2);
            $table->timestamp('paid_at');
            $table->enum('payment_method', PaymentMethod::values())->nullable();
            $table->enum('status', PaymentStatus::values())->nullable()->default(PaymentStatus::Unpaid->value);
            $table->foreignId('recorded_by')->nullable()->constrained('users')->nullOnDelete();
            $table->text('notes')->nullable();
            $table->timestamps();
        });
    }

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