<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Rules;

final class RulesStatistics
{
    public static function from(array $ruleSets, array $decisionTables, array $results): array
    {
        $rules = 0;
        $matched = 0;
        $actions = 0;

        foreach ($ruleSets as $ruleSet) {
            $rules += count((array) ($ruleSet['rules'] ?? []));
        }

        foreach ($results as $result) {
            if (($result['matched'] ?? false) === true) {
                $matched++;
            }
            $actions += count((array) ($result['actions'] ?? []));
        }

        return [
            'ruleSets' => count($ruleSets),
            'rules' => $rules,
            'decisionTables' => count($decisionTables),
            'evaluations' => count($results),
            'matchedEvaluations' => $matched,
            'actions' => $actions,
        ];
    }
}
