<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {

    public function up()
    {
        Schema::create('merit_increase_matrices', function (Blueprint $table) {
            $table->id();
            $table->string('performance_tercile'); // e.g. T1, T2, T3
            $table->decimal('pos_min', 8, 2);
            $table->decimal('pos_max', 8, 2);

            // Each column group = performance category
            $table->decimal('outstanding_min', 5, 2)->nullable();
            $table->decimal('outstanding_target', 5, 2)->nullable();
            $table->decimal('outstanding_max', 5, 2)->nullable();

            $table->decimal('exceeded_min', 5, 2)->nullable();
            $table->decimal('exceeded_target', 5, 2)->nullable();
            $table->decimal('exceeded_max', 5, 2)->nullable();

            $table->decimal('achieved_min', 5, 2)->nullable();
            $table->decimal('achieved_target', 5, 2)->nullable();
            $table->decimal('achieved_max', 5, 2)->nullable();

            $table->decimal('partially_met_min', 5, 2)->nullable();
            $table->decimal('partially_met_target', 5, 2)->nullable();
            $table->decimal('partially_met_max', 5, 2)->nullable();

            $table->decimal('below_min', 5, 2)->nullable();
            $table->decimal('below_target', 5, 2)->nullable();
            $table->decimal('below_max', 5, 2)->nullable();

            $table->timestamps();

            $table->foreignId('organisation_id')->constrained()->cascadeOnDelete();
            $table->foreignId('job_grade_id')->constrained()->cascadeOnDelete();

        });
    }

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

