<?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::table('tagihan', function (Blueprint $table) {
            // Add a composite unique index to prevent duplicate tagihan entries.
            // Columns: siswa_id, kelas_id, tarif_pembayaran_id, tahun_ajaran_id, bulan (nullable).
            // The index name is explicit to avoid naming conflicts.
            $table->unique([
                'siswa_id',
                'kelas_id',
                'tarif_pembayaran_id',
                'tahun_ajaran_id',
                'bulan',
            ], 'tagihan_unique_composite');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('tagihan', function (Blueprint $table) {
            $table->dropUnique('tagihan_unique_composite');
        });
    }
};
