<?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('themes', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('tenant_id')->nullable()->index();
            $table->string('slug', 80);
            $table->string('name', 120);
            $table->string('version', 32)->default('1.0.0');
            $table->string('author', 120)->nullable();
            $table->text('description')->nullable();
            $table->string('path', 255);
            $table->string('screenshot_url', 255)->nullable();
            $table->enum('type', ['core', 'community', 'premium'])->default('community');
            $table->boolean('is_active')->default(false);
            $table->json('settings')->nullable();
            $table->json('manifest')->nullable();
            $table->timestamp('installed_at')->nullable();
            $table->timestamps();

            $table->unique(['tenant_id', 'slug']);
            $table->index(['tenant_id', 'is_active']);
        });
    }

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