<?php

declare(strict_types=1);

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('academy_lessons', function (Blueprint $table): void {
            $table->unsignedInteger('lesson_number')->nullable()->after('slug');
            $table->unsignedInteger('course_order')->nullable()->after('lesson_number');
            $table->string('series_name', 120)->nullable()->after('course_order');

            $table->index(['series_name', 'course_order', 'lesson_number'], 'academy_lessons_series_course_order_index');
        });
    }

    public function down(): void
    {
        Schema::table('academy_lessons', function (Blueprint $table): void {
            $table->dropIndex('academy_lessons_series_course_order_index');
            $table->dropColumn(['lesson_number', 'course_order', 'series_name']);
        });
    }
};