<?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::create('domain_categories', function (Blueprint $table) {
            $table->id();

            // Self-referencing so administrators can nest categories if needed.
            $table->foreignId('parent_id')->nullable()->constrained('domain_categories')->nullOnDelete();

            $table->string('name');
            $table->string('slug')->unique();
            $table->text('description')->nullable();

            // Lucide icon name resolved by the SPA; no binary assets in the DB.
            $table->string('icon', 64)->nullable();

            $table->boolean('is_active')->default(true);
            $table->boolean('is_featured')->default(false);
            $table->unsignedSmallInteger('sort_order')->default(0);

            // Denormalised counter maintained by the listing service.
            $table->unsignedInteger('listings_count')->default(0);

            $table->string('seo_title')->nullable();
            $table->string('seo_description', 320)->nullable();

            $table->timestamps();
            $table->softDeletes();

            $table->index(['is_active', 'sort_order']);
            $table->index(['is_featured', 'is_active']);
        });
    }

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