<?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('serenata_payments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('organization_id')->constrained('organizations')->cascadeOnDelete();
            $table->foreignId('serenata_id')->constrained('serenatas')->cascadeOnDelete();
            $table->foreignId('payment_method_id')->nullable()->constrained('payment_methods')->nullOnDelete();
            $table->foreignId('registered_by_user_id')->constrained('users')->cascadeOnDelete();
            $table->dateTime('paid_at');
            $table->string('payment_method_name', 120);
            $table->string('transaction_reference', 190)->nullable();
            $table->decimal('amount', 12, 2)->default(0);
            $table->text('note')->nullable();
            $table->timestamps();

            $table->index(['organization_id', 'serenata_id']);
            $table->index(['serenata_id', 'paid_at']);
        });
    }

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