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

final class ContainerGraphCommand extends AbstractCommand
{
    public function name(): string { return 'container:graph'; }
    public function description(): string { return 'Show integrated DI dependency graph.'; }

    public function handle(array $arguments = []): int
    {
        $container = (new PlatformContainerRuntime(ConsolePath::basePath()))->container();
        $graph = (new DependencyGraphBuilder())->build($container->definitionRepository());
        $this->json($graph->toArray());
        return 0;
    }
}
