| | | 1 | | using Intentum.Core.Intents; |
| | | 2 | | using Intentum.Runtime.Policy; |
| | | 3 | | |
| | | 4 | | namespace Intentum.Runtime.Engine; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Context-aware policy evaluation: decides using both intent and context (system load, region, etc.). |
| | | 8 | | /// </summary> |
| | | 9 | | public static class ContextAwarePolicyEngine |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Evaluates the intent with the given context and context-aware policy. |
| | | 13 | | /// First matching rule wins; default is Observe. |
| | | 14 | | /// </summary> |
| | | 15 | | public static PolicyDecision Evaluate( |
| | | 16 | | Intent intent, |
| | | 17 | | PolicyContext context, |
| | | 18 | | ContextAwareIntentPolicy policy) |
| | 3 | 19 | | { |
| | 5 | 20 | | var matchingRule = policy.Rules.FirstOrDefault(rule => rule.Condition(intent, context)); |
| | 3 | 21 | | return matchingRule?.Decision ?? PolicyDecision.Observe; |
| | 3 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Evaluates and returns the decision plus the matched rule (if any). |
| | | 26 | | /// </summary> |
| | | 27 | | public static (PolicyDecision Decision, ContextAwarePolicyRule? MatchedRule) EvaluateWithRule( |
| | | 28 | | Intent intent, |
| | | 29 | | PolicyContext context, |
| | | 30 | | ContextAwareIntentPolicy policy) |
| | 2 | 31 | | { |
| | 3 | 32 | | var matchingRule = policy.Rules.FirstOrDefault(rule => rule.Condition(intent, context)); |
| | 2 | 33 | | var decision = matchingRule?.Decision ?? PolicyDecision.Observe; |
| | 2 | 34 | | return (decision, matchingRule); |
| | 2 | 35 | | } |
| | | 36 | | } |