<?php
namespace Root\Core\Quantum;

class QRouter
{
    private array $rules = [];

    public function addRule(callable $predicate, callable $action): void
    {
        $this->rules[] = compact('predicate', 'action');
    }

    public function route(mixed $input): mixed
    {
        foreach ($this->rules as $rule) {
            if (($rule['predicate'])($input)) {
                return ($rule['action'])($input);
            }
        }
        return null;
    }
}
