<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Sourcing\Compaction;

final class EventCompactionStatistics
{
    public static function from(array $results, array $archives): array
    {
        $compacted = 0;
        $before = 0;
        $after = 0;

        foreach ($results as $result) {
            $compacted += (int) ($result['compactedCount'] ?? 0);
            $before += (int) ($result['beforeCount'] ?? 0);
            $after += (int) ($result['afterCount'] ?? 0);
        }

        $archived = 0;
        foreach ($archives as $archive) {
            $archived += (int) ($archive['archivedCount'] ?? 0);
        }

        return [
            'streams' => count($results),
            'beforeEvents' => $before,
            'afterEvents' => $after,
            'compactedEvents' => $compacted,
            'archives' => count($archives),
            'archivedEvents' => $archived,
        ];
    }
}
