<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\DI\Compiler\Pipeline;

final class CompilerPipelineAudit
{
    private array $entries = [];

    public function record(string $stage, float $timeMs): void
    {
        $this->entries[] = ['stage' => $stage, 'timeMs' => round($timeMs, 3)];
    }

    public function entries(): array { return $this->entries; }
    public function stageNames(): array { return array_map(static fn (array $entry): string => $entry['stage'], $this->entries); }
    public function totalMs(): float { return round(array_sum(array_map(static fn (array $entry): float => (float)$entry['timeMs'], $this->entries)), 3); }
    public function toArray(): array { return ['stages' => $this->entries, 'stageNames' => $this->stageNames(), 'totalMs' => $this->totalMs()]; }
}
