<?php
declare(strict_types=1);

use Celena\Core\Database\Blueprint;
use Celena\Core\Database\Connection;
use Celena\Core\Database\Schema;

return function (Schema $schema, Connection $conn): void {
    $schema->create('celena_comments', function (Blueprint $t) {
        $t->id();
        $t->string('entity_type', 32)->default('news');
        $t->bigInteger('entity_id');
        $t->bigInteger('parent_id')->nullable();
        $t->bigInteger('user_id')->nullable();
        $t->string('author_name', 191)->nullable();
        $t->string('author_email', 191)->nullable();
        $t->text('body');
        $t->string('status', 16)->default('pending'); // pending, approved, spam, trash
        $t->string('ip', 45)->nullable();
        $t->datetime('created_at');
        $t->datetime('updated_at')->nullable();
        $t->index(['entity_type', 'entity_id'], 'comments_entity');
        $t->index('status');
        $t->index('parent_id');
    });
};
