<?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\EventVerificationService;

final class EventsVerifyCommand extends AbstractCommand
{
    public function name(): string { return 'events:verify'; }
    public function description(): string { return 'Verify Event Core subsystem.'; }

    public function handle(array $arguments = []): int
    {
        $service = new EventVerificationService();
        $status = $service->verifyAndWriteReport(ConsolePath::basePath());

        $this->title('PPphp Event Core Verification');
        $this->line('Status: ' . ($status->ok() ? 'PASS' : 'FAIL'));

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

        $summary = $status->summary();
        $this->line('Listeners: ' . ($summary['listeners'] ?? 0));
        $this->line('Handled: ' . ($summary['handled'] ?? 0));
        $this->line('Score: ' . ($summary['score'] ?? 0) . '%');
        $this->line('Report: ' . EventVerificationService::REPORT_FILE);

        return $status->ok() ? 0 : 1;
    }
}
