<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class StreamPublishCommand extends AbstractCommand
{
    public function name(): string { return 'stream:publish'; }
    public function description(): string { return 'PPphp Stream Publish'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Stream Publish');
        $result = \PpPhp\Core\Platform\Event\Streaming\Publisher\PublisherManager::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath())->publish(\PpPhp\Core\Platform\Event\Streaming\Publisher\PublishRequest::create('console.publisher', 'console.stream', 'console.message', ['sample' => true], ['source' => 'console'])); $this->line('Published: ' . ($result->published() ? 'YES' : 'NO')); $this->line('Message: ' . $result->messageId());
        return 0;
    }
}
