<?php

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

/**
 * Composite indexes for the evaluation module's hot query paths — review queue,
 * dashboards, reference-period lookups and integrity peer/shift queries.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('monthly_evaluations', function (Blueprint $table) {
            $table->index(['status', 'branch_id'], 'me_status_branch');
            $table->index(['class_id', 'template_id'], 'me_class_template');
        });
        Schema::table('review_flags', function (Blueprint $table) {
            $table->index('monthly_evaluation_id', 'rf_eval');
        });
        Schema::table('template_assignments', function (Blueprint $table) {
            $table->index('evaluator_id', 'ta_evaluator');
        });
        Schema::table('evaluation_reviews', function (Blueprint $table) {
            $table->index(['monthly_evaluation_id', 'acted_at'], 'er_eval_acted');
        });
    }

    public function down(): void
    {
        Schema::table('monthly_evaluations', function (Blueprint $table) {
            $table->dropIndex('me_status_branch');
            $table->dropIndex('me_class_template');
        });
        Schema::table('review_flags', fn (Blueprint $t) => $t->dropIndex('rf_eval'));
        Schema::table('template_assignments', fn (Blueprint $t) => $t->dropIndex('ta_evaluator'));
        Schema::table('evaluation_reviews', fn (Blueprint $t) => $t->dropIndex('er_eval_acted'));
    }
};
