<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;
use PpPhp\Core\Platform\Event\Scheduler\EventScheduler;

final class SchedulerListCommand extends AbstractCommand
{
    public function name(): string { return 'scheduler:list'; }
    public function description(): string { return 'List scheduled events.'; }

    public function handle(array $arguments = []): int
    {
        $scheduler = new EventScheduler();
        $scheduler->dispatchLater('scheduler.console.sample', 30);
        $this->title('PPphp Scheduled Events');
        foreach ($scheduler->snapshot()->events() as $event) {
            $this->line('- ' . $event['id'] . ' ' . $event['eventName'] . ' @ ' . $event['runAt']);
        }
        return 0;
    }
}
