<?php

declare(strict_types=1);

namespace App\Framework\SlidingWindow\Aggregator;

use App\Framework\SlidingWindow\WindowEntry;

/**
 * Aggregator for counting entries - useful for RateLimiter
 *
 * @implements SlidingWindowAggregator<CountingResult>
 */
final readonly class CountingAggregator implements SlidingWindowAggregator
{
    public function aggregate(WindowEntry ...$entries): CountingResult
    {
        return new CountingResult(
            count: count($entries),
            values: array_map(fn (WindowEntry $entry) => $entry->value, $entries)
        );
    }

    public function getIdentifier(): string
    {
        return 'counting';
    }
}
