<?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::create('academy_lessons', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('category_id')->nullable()->constrained('academy_categories')->nullOnDelete();
            $table->string('title');
            $table->string('slug')->unique();
            $table->text('excerpt')->nullable();
            $table->longText('content')->nullable();
            $table->string('difficulty')->default('beginner');
            $table->string('access_level')->default('free');
            $table->string('lesson_type')->default('article');
            $table->string('cover_image')->nullable();
            $table->string('video_url')->nullable();
            $table->unsignedInteger('reading_minutes')->default(5);
            $table->boolean('featured')->default(false);
            $table->boolean('active')->default(true);
            $table->timestamp('published_at')->nullable();
            $table->string('seo_title')->nullable();
            $table->text('seo_description')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index(['active', 'featured', 'access_level']);
            $table->index(['published_at', 'active']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('academy_lessons');
    }
};