<?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\Compiler\EventCompilerPaths;
use PpPhp\Core\Platform\Event\Compiler\EventCompilerService;

final class EventsCompileCommand extends AbstractCommand
{
    public function name(): string { return 'events:compile'; }
    public function description(): string { return 'Compile Event subsystem cache artifacts.'; }

    public function handle(array $arguments = []): int
    {
        $report = EventCompilerService::default()->compile(ConsolePath::basePath())->toArray();
        $this->title('PPphp Event Compiler');
        $this->line('Stages: ' . count($report['stages']));
        $this->line('Artifacts: ' . count($report['artifacts']));
        $this->line('Warnings: ' . count($report['warnings']));
        $this->line('Report: ' . EventCompilerPaths::REPORT_FILE);
        return count($report['warnings']) === 0 ? 0 : 1;
    }
}
