<?php

declare(strict_types=1);

namespace App\Framework\SlidingWindow\Aggregator;

/**
 * Result of numeric aggregation
 */
final readonly class NumericResult
{
    public function __construct(
        public int $count,
        public float $sum,
        public float $average,
        public ?float $min,
        public ?float $max,
        public ?float $median,
        public ?float $percentile95,
    ) {
    }

    public function isEmpty(): bool
    {
        return $this->count === 0;
    }

    public function hasMinimumSamples(int $minimum): bool
    {
        return $this->count >= $minimum;
    }

    public function isAverageAbove(float $threshold): bool
    {
        return $this->average > $threshold;
    }

    public function isPercentile95Above(float $threshold): bool
    {
        return $this->percentile95 !== null && $this->percentile95 > $threshold;
    }

    public function toArray(): array
    {
        return [
            'count' => $this->count,
            'sum' => $this->sum,
            'average' => $this->average,
            'min' => $this->min,
            'max' => $this->max,
            'median' => $this->median,
            'percentile_95' => $this->percentile95,
        ];
    }
}
