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

final class ContainerFactoriesCommand extends AbstractCommand
{
    public function name(): string { return 'container:factories'; }
    public function description(): string { return 'List generated DI factories.'; }

    public function handle(array $arguments = []): int
    {
        $base = ConsolePath::basePath();
        $dir = FactoryCachePaths::directory($base);
        $files = is_dir($dir) ? glob($dir . '/*.php') : [];

        $this->title('PPphp DI Generated Factories');
        $this->line('Directory: ' . FactoryCachePaths::relativeDirectory());
        $this->line('Factories: ' . count($files ?: []));

        foreach (array_slice($files ?: [], 0, 25) as $file) {
            $this->line('- ' . basename($file));
        }

        if (count($files ?: []) > 25) {
            $this->line('... ' . (count($files) - 25) . ' more');
        }

        return 0;
    }
}
