<?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('manuals', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignUuid('tenant_id')->constrained('tenants')->cascadeOnDelete();
            $table->string('version', 20)->default('v1.0');
            $table->string('slug', 191);
            $table->string('title', 255);
            $table->uuid('parent_id')->nullable();
            $table->longText('content')->nullable();
            $table->integer('order_sort')->default(0);
            $table->boolean('is_published')->default(true);
            $table->timestamps();
            $table->softDeletes();

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

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