<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * Add indexes on columns used for searching and filtering
     */
    public function up(): void
    {
        // Index for File title search (LIKE queries)
        Schema::table('filedata', function (Blueprint $table) {
            $table->index('title')->after('title');
        });

        // Index for Group name search (LIKE queries)
        Schema::table('_groups', function (Blueprint $table) {
            $table->index('group_name')->after('group_name');
        });

        // Indexes for Code filtering and searching
        Schema::table('codes', function (Blueprint $table) {
            $table->index('status')->after('status');
            $table->index('created_at')->after('created_at');
        });

        // Index for BannedIp search (LIKE queries)
        Schema::table('bannedips', function (Blueprint $table) {
            $table->index('ip_address')->after('ip_address');
        });

        // Index for DeviceList mac_address search (LIKE queries)
        Schema::table('device_lists', function (Blueprint $table) {
            $table->index('mac_address')->after('mac_address');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('filedata', function (Blueprint $table) {
            $table->dropIndex(['title']);
        });

        Schema::table('_groups', function (Blueprint $table) {
            $table->dropIndex(['group_name']);
        });

        Schema::table('codes', function (Blueprint $table) {
            $table->dropIndex(['status']);
            $table->dropIndex(['created_at']);
        });

        Schema::table('bannedips', function (Blueprint $table) {
            $table->dropIndex(['ip_address']);
        });

        Schema::table('device_lists', function (Blueprint $table) {
            $table->dropIndex(['mac_address']);
        });
    }
};
