<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class SagaStartCommand extends AbstractCommand
{
    public function name(): string { return 'saga:start'; }
    public function description(): string { return 'PPphp Saga Start'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Saga Start');
        $runtime = \PpPhp\Core\Platform\Event\Sourcing\Saga\SagaRuntime::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath()); $runtime->register(\PpPhp\Core\Platform\Event\Sourcing\Saga\SagaDefinition::create('console_saga', 'Console Saga', 'ConsoleStarted', [\PpPhp\Core\Platform\Event\Sourcing\Saga\SagaStep::create('console_step', 'ConsoleCommand', 'ConsoleAggregate', ['handled' => true])->toArray()])); $instances = $runtime->startFromEvent(\PpPhp\Core\Platform\Event\Sourcing\Domain\DomainEventEnvelope::fromStoredEvent(['eventId' => 'evt_console_saga', 'eventType' => 'ConsoleStarted', 'aggregateId' => 'console-saga', 'aggregateType' => 'Console', 'sequence' => 1])); $this->line('Started: ' . count($instances)); if ($instances !== []) { $this->line('Instance: ' . $instances[0]->instanceId()); }
        return 0;
    }
}
