<?php

declare(strict_types=1);

namespace App\Framework\Discovery\Processing;

use App\Framework\Core\ValueObjects\Byte;

/**
 * Collection of processing chunks
 */
final readonly class ChunkCollection implements \Countable
{
    public function __construct(
        private array $chunks
    ) {
    }

    public function getChunks(): array
    {
        return $this->chunks;
    }

    public function count(): int
    {
        return count($this->chunks);
    }

    public function getTotalFileCount(): int
    {
        return array_sum(array_map(fn (ProcessingChunk $chunk) => $chunk->getFileCount(), $this->chunks));
    }

    public function getTotalSize(): Byte
    {
        return array_reduce(
            $this->chunks,
            fn (Byte $total, ProcessingChunk $chunk) => $total->add($chunk->getTotalSize()),
            Byte::zero()
        );
    }
}
