<?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\DI\Verification\DiSubsystemVerifier;

final class ContainerVerifyCommand extends AbstractCommand
{
    public function name(): string { return 'container:verify'; }
    public function description(): string { return 'Verify the full DI subsystem.'; }

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

        $this->title('PPphp DI Subsystem 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('Definitions: ' . ($summary['definitions'] ?? 0));
        $this->line('Factories: ' . ($summary['factoriesGenerated'] ?? 0));
        $this->line('Validation score: ' . ($summary['validationScore'] ?? 0) . '%');

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