<?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('comments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('post_id')->constrained()->cascadeOnDelete();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->string('author_name', 50);
            $table->string('author_email', 255)->nullable();
            $table->string('author_url', 255)->nullable();
            $table->mediumText('content');
            $table->string('ip', 64)->nullable();
            $table->string('status', 20)->default('pending')->index();
            $table->json('ai_review')->nullable();
            $table->timestamp('created_at')->useCurrent();

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

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