<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;
use PpPhp\Core\Platform\Console\ConsolePath;
use PpPhp\Core\Platform\Event\Verification\ListenerRegistryVerifier;

final class ListenersVerifyCommand extends AbstractCommand
{
    public function name(): string { return 'listeners:verify'; }
    public function description(): string { return 'Verify listener registry subsystem.'; }

    public function handle(array $arguments = []): int
    {
        $result = (new ListenerRegistryVerifier())->verify(ConsolePath::basePath());

        $this->title('PPphp Listener Registry Verification');
        $this->line('Status: ' . ($result['ok'] ? 'PASS' : 'FAIL'));

        foreach ($result['checks'] as $check => $ok) {
            $this->line(($ok ? '[PASS] ' : '[FAIL] ') . $check);
        }

        $this->line('Score: ' . ($result['summary']['score'] ?? 0) . '%');
        return $result['ok'] ? 0 : 1;
    }
}
