<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class EventUpcastCommand extends AbstractCommand
{
    public function name(): string { return 'event:upcast'; }
    public function description(): string { return 'PPphp Event Upcast'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Event Upcast');
        $runtime = \PpPhp\Core\Platform\Event\Sourcing\Versioning\EventVersioningRuntime::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath()); $runtime->registerVersion(\PpPhp\Core\Platform\Event\Sourcing\Versioning\EventVersion::create('ConsoleEventHandled', 2, 'console-event-v2')); $runtime->registerUpcaster(\PpPhp\Core\Platform\Event\Sourcing\Versioning\EventUpcaster::create('console_event_v1_to_v2', 'ConsoleEventHandled', 1, 2, ['handled' => 'processed'], ['source' => 'console'])); $result = $runtime->upcast(['eventId' => 'evt_console_upcast', 'eventType' => 'ConsoleEventHandled', 'payload' => ['handled' => true], 'metadata' => ['eventVersion' => 1]]); $this->line('Upcasted: ' . ($result->upcasted() ? 'YES' : 'NO'));
        return 0;
    }
}
