<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class QueryFindCommand extends AbstractCommand
{
    public function name(): string { return 'query:find'; }
    public function description(): string { return 'PPphp Query Find'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Query Find');
        $runtime = \PpPhp\Core\Platform\Event\Sourcing\Query\QueryRuntime::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath()); $runtime->register(\PpPhp\Core\Platform\Event\Sourcing\Query\ReadModelDefinition::create('console_read_model', 'console_projection', 'Console Read Model', ['aggregateId', 'state'])); $row = $runtime->find('console_read_model', 'console-aggregate'); $this->line('Found: ' . (is_array($row) ? 'YES' : 'NO')); if (is_array($row)) { $this->line('Aggregate: ' . ($row['aggregateId'] ?? '')); }
        return 0;
    }
}
