<?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('nova_card_comments', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('card_id')->constrained('nova_cards')->cascadeOnDelete();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('parent_id')->nullable()->constrained('nova_card_comments')->nullOnDelete();
            $table->text('body');
            $table->text('rendered_body')->nullable();
            $table->string('status', 24)->default('visible');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['card_id', 'status', 'created_at']);
        });
    }

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