<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * Adds performance indices for lesson progress queries
     */
    public function up(): void
    {
        Schema::table('lms_lesson_progress', function (Blueprint $table) {
            // Index for counting completed lessons per user/course
            $table->index(['user_id', 'course_id', 'completed'], 'idx_user_course_completed');
        });

        // Index on lms_course_sections for course_id lookups
        Schema::table('lms_course_sections', function (Blueprint $table) {
            if (!Schema::hasIndex('lms_course_sections', 'lms_course_sections_course_id_index')) {
                $table->index('course_id');
            }
        });
    }

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