<?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\Lifecycle\LifecycleEventVerifier;

final class LifecycleVerifyCommand extends AbstractCommand
{
    public function name(): string { return 'lifecycle:verify'; }
    public function description(): string { return 'Verify lifecycle events.'; }

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