<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->index('task_status_id');
            $table->index('project_module_id');
            $table->index('created_by');
            $table->index('deadline');
            $table->index('priority');
        });

        Schema::table('bugs', function (Blueprint $table) {
            $table->index('project_id');
            $table->index('module_id');
            $table->index('reported_by');
            $table->index('assigned_to');
            $table->index('severity');
            $table->index('status');
        });

        Schema::table('point_transactions', function (Blueprint $table) {
            $table->index('user_id');
            $table->index('type');
            $table->index('source');
            $table->index('created_at');
        });

        Schema::table('monthly_leaderboards', function (Blueprint $table) {
            $table->index(['year', 'month', 'total_points']);
        });

        Schema::table('time_logs', function (Blueprint $table) {
            $table->index('task_id');
            $table->index('status');
        });
    }

    public function down(): void
    {
        Schema::table('tasks', function (Blueprint $table) {
            $table->dropIndex(['task_status_id']);
            $table->dropIndex(['project_module_id']);
            $table->dropIndex(['created_by']);
            $table->dropIndex(['deadline']);
            $table->dropIndex(['priority']);
        });

        Schema::table('bugs', function (Blueprint $table) {
            $table->dropIndex(['project_id']);
            $table->dropIndex(['module_id']);
            $table->dropIndex(['reported_by']);
            $table->dropIndex(['assigned_to']);
            $table->dropIndex(['severity']);
            $table->dropIndex(['status']);
        });

        Schema::table('point_transactions', function (Blueprint $table) {
            $table->dropIndex(['user_id']);
            $table->dropIndex(['type']);
            $table->dropIndex(['source']);
            $table->dropIndex(['created_at']);
        });

        Schema::table('monthly_leaderboards', function (Blueprint $table) {
            $table->dropIndex(['year', 'month', 'total_points']);
        });

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