using System.Collections.Immutable; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using StellaOps.PolicyDsl; using StellaOps.Policy.Engine.Evaluation; namespace StellaOps.Policy.Engine.Services; internal sealed partial class PolicyEvaluationService { private readonly PolicyEvaluator _evaluator; private readonly PathScopeMetrics _pathMetrics; private readonly ILogger _logger; public PolicyEvaluationService() : this(new PathScopeMetrics(), NullLogger.Instance, new PolicyEvaluator()) { } public PolicyEvaluationService(PathScopeMetrics pathMetrics, ILogger logger, PolicyEvaluator evaluator) { _pathMetrics = pathMetrics ?? throw new ArgumentNullException(nameof(pathMetrics)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _evaluator = evaluator ?? throw new ArgumentNullException(nameof(evaluator)); } internal Evaluation.PolicyEvaluationResult Evaluate(PolicyIrDocument document, Evaluation.PolicyEvaluationContext context) { if (document is null) { throw new ArgumentNullException(nameof(document)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } var request = new Evaluation.PolicyEvaluationRequest(document, context); return _evaluator.Evaluate(request); } // PathScopeSimulationService partial class relies on _pathMetrics. }