<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Rules\Repository;

final class RuleRepositoryStatistics
{
    public static function from(array $entries): array
    {
        $active = 0;
        $inactive = 0;
        $ruleSets = [];

        foreach ($entries as $entry) {
            if (($entry['status'] ?? 'active') === 'active') {
                $active++;
            } else {
                $inactive++;
            }

            $ruleSetId = (string) ($entry['ruleSetId'] ?? '');
            if ($ruleSetId !== '') {
                $ruleSets[$ruleSetId] = true;
            }
        }

        return [
            'entries' => count($entries),
            'active' => $active,
            'inactive' => $inactive,
            'ruleSets' => count($ruleSets),
        ];
    }
}
