using SQLInsight.Core.Findings; namespace SQLInsight.Rules.Engine; /// /// What a rule concluded. Created through the static factory methods. /// public sealed record RuleEvaluation { private RuleEvaluation(RuleOutcome outcome, IReadOnlyList findings, string? reason) { Outcome = outcome; Findings = findings; Reason = reason; } public RuleOutcome Outcome { get; } public IReadOnlyList Findings { get; } /// Why the rule could not be measured, if it could not. public string? Reason { get; } public static RuleEvaluation Passed() => new(RuleOutcome.Passed, [], null); public static RuleEvaluation Found(params Finding[] findings) { ArgumentNullException.ThrowIfNull(findings); if (findings.Length == 0) { throw new ArgumentException("At least one finding is required. Use Passed() when there is none.", nameof(findings)); } return new(RuleOutcome.Findings, findings, null); } public static RuleEvaluation NotMeasurable(string reason) => new(RuleOutcome.NotMeasurable, [], reason); public static RuleEvaluation NotApplicable(string reason) => new(RuleOutcome.NotApplicable, [], reason); } public enum RuleOutcome { /// The rule ran and found nothing wrong. Passed, /// The rule ran and found one or more problems. Findings, /// The rule could not be evaluated on this instance. This is never the same as . NotMeasurable, /// The rule failed while running. This is never the same as . Error, /// /// The rule does not apply to this kind of instance: its SQL Server version lacks what the rule looks at (Query /// Store on 2005 …), or Azure manages it. Not a gap in the monitoring, so not counted as not measurable. /// Last in the enum: outcomes are stored as numbers. /// NotApplicable, }