<?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\Compiler\EventCompilerVerifier;

final class EventsCompilerVerifyCommand extends AbstractCommand
{
    public function name(): string { return 'events:compiler:verify'; }
    public function description(): string { return 'Verify Event compiler artifacts.'; }

    public function handle(array $arguments = []): int
    {
        $result = (new EventCompilerVerifier())->verify(ConsolePath::basePath());
        $this->title('PPphp Event Compiler 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;
    }
}
