<?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('modernization_pages', function (Blueprint $table) {
            $table->id();
            $table->foreignId('parent_id')->nullable()->constrained('modernization_pages')->nullOnDelete();
            $table->string('slug')->unique();
            $table->string('legacy_path')->nullable()->unique();
            $table->string('kind', 30)->default('article');
            $table->string('title');
            $table->string('eyebrow')->nullable();
            $table->text('summary');
            $table->longText('body')->nullable();
            $table->string('existing_image')->nullable();
            $table->string('icon', 40)->nullable();
            $table->string('related_service_slug')->nullable();
            $table->unsignedInteger('sort_order')->default(0);
            $table->boolean('is_published')->default(true);
            $table->string('meta_title')->nullable();
            $table->text('meta_description')->nullable();
            $table->timestamps();

            $table->index(['kind', 'is_published', 'sort_order']);
        });
    }

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