<?php

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

/**
 * Per-student fee overrides. When a row exists for (student, fee_type) its amount
 * is used instead of the class-wide Fee Structure default. Set at admission and
 * editable from the student profile.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('student_fee_heads', function (Blueprint $table) {
            $table->id();
            $table->foreignId('branch_id')->constrained('branches')->cascadeOnUpdate()->restrictOnDelete();
            $table->foreignId('student_id')->constrained('students')->cascadeOnDelete();
            $table->foreignId('fee_type_id')->constrained('fee_types')->cascadeOnDelete();
            $table->decimal('amount', 12, 2)->default(0);
            $table->timestamps();

            $table->unique(['student_id', 'fee_type_id']);
        });
    }

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