<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;
use PpPhp\Core\Platform\Event\Queue\DeferredQueueManager;

final class QueueListCommand extends AbstractCommand
{
    public function name(): string { return 'queue:list'; }
    public function description(): string { return 'List deferred queue events.'; }

    public function handle(array $arguments = []): int
    {
        $manager = new DeferredQueueManager();
        $manager->enqueue('queue.console.sample', ['source' => 'console']);
        $this->title('PPphp Deferred Queue Events');
        foreach ($manager->snapshot()->events() as $event) {
            $this->line('- ' . $event['id'] . ' ' . $event['eventName']);
        }
        return 0;
    }
}
