<?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_jobs', function (Blueprint $t) {
        $t->id();
        $t->string('queue', 64)->default('default');
        $t->string('handler', 191);
        $t->text('payload');
        $t->integer('attempts')->default(0);
        $t->integer('max_attempts')->default(3);
        $t->datetime('available_at');
        $t->datetime('reserved_at')->nullable();
        $t->datetime('completed_at')->nullable();
        $t->text('last_error')->nullable();
        $t->datetime('created_at');
        $t->index('queue');
        $t->index('available_at');
    });
};
