<?php

namespace App\Services\Communications\Routing;

class CallRoutingEngine {
    /**
     * @param array<int, RoutingRule> $rules
     */
    public function __construct(
        protected array $rules,
    ) {
    }

    public function resolve(RoutingContext $context): RoutingDecision {
        foreach ($this->rules as $rule) {
            $decision = $rule->handle($context);

            if ($decision !== null) {
                return $decision;
            }
        }

        return RoutingDecision::voicemail('no_routing_rule_matched');
    }
}