<?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 SchedulerRunCommand extends AbstractCommand
{
    public function name(): string { return 'scheduler:run'; }
    public function description(): string { return 'Run due scheduled events.'; }

    public function handle(array $arguments = []): int
    {
        $scheduler = new EventScheduler();
        $scheduler->dispatchLater('scheduler.run.sample', 0);
        $executed = $scheduler->run(static function (): void {});
        $this->title('PPphp Scheduler Run');
        $this->line('Executed: ' . $executed);
        return 0;
    }
}
