<?php

namespace App\Torrentio\Client\Rule;

class RuleEngine
{
    private array $rules = [];

    public function addRule(callable $rule): void
    {
        $this->rules[] = $rule;
    }

    public function validateAny($fact): bool
    {
        foreach ($this->rules as $rule) {
            if ($rule($fact)) {
                return true;
            }
        }
        return false;
    }

    public function validateAll($fact): bool
    {
        foreach ($this->rules as $rule) {
            if (!$rule($fact)) {
                return false;
            }
        }

        return true;
    }
}