<?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\Integration\PlatformContainerRuntime;
use PpPhp\Core\Platform\DI\Validation\ContainerValidator;

final class ContainerValidateCommand extends AbstractCommand
{
    public function name(): string { return 'container:validate'; }
    public function description(): string { return 'Validate integrated DI container definitions.'; }

    public function handle(array $arguments = []): int
    {
        $container = (new PlatformContainerRuntime(ConsolePath::basePath()))->container();
        $result = (new ContainerValidator())->validate($container->definitionRepository());

        $this->title('PPphp DI Container Validation');
        $this->line('Definitions: ' . count($container->definitions()));
        $this->line('Score: ' . $result->score() . '%');
        $this->line('Errors: ' . count($result->errors()) . ' | Warnings: ' . count($result->warnings()));

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