<?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 {
         // 1. Tambahkan Index di tabel link_profiles (Jika belum unique)
         Schema::table('link_profiles', function(Blueprint $table) {
            // Kita gunakan index biasa agar pencarian WHERE npsn = ... lebih kencang
            // Jika sudah ada unique(), ini opsional, tapi menambahkannya tidak merusak.
            $table->index('link_profile_npsn', 'idx_profile_npsn');
         });
         // 2. Tambahkan Index di tabel links (Sangat Penting!)
         // Karena di Controller kamu pakai: ->where('is_active', true)->where('is_cbt_offline', true)
         Schema::table('links', function(Blueprint $table) {
            $table->index(['link_profile_id', 'is_active', 'is_cbt_offline'], 'idx_links_filter');
            $table->index('order'); // Untuk mempercepat orderBy('order')
         });
      }

      /**
       * Reverse the migrations.
       */
      public function down(): void {
         Schema::table('link_profiles', function(Blueprint $table) {
            $table->dropIndex('idx_profile_npsn');
         });
         Schema::table('links', function(Blueprint $table) {
            $table->dropIndex('idx_links_filter');
            $table->dropIndex(['order']);
         });
      }
   };