|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Identifies commercial evidence execution blocker kinds. |
| 5 | +/// </summary> |
| 6 | +public enum SigtranCommercialEvidenceExecutionBlockerKind |
| 7 | +{ |
| 8 | + /// <summary>Readiness preflight blocker.</summary> |
| 9 | + ReadinessPreflight, |
| 10 | + |
| 11 | + /// <summary>Missing or mismatched execution environment variable.</summary> |
| 12 | + Environment, |
| 13 | + |
| 14 | + /// <summary>Stage command failure.</summary> |
| 15 | + CommandFailure, |
| 16 | + |
| 17 | + /// <summary>Native SCTP host capability blocker.</summary> |
| 18 | + NativeSctp, |
| 19 | + |
| 20 | + /// <summary>External peer availability blocker.</summary> |
| 21 | + ExternalPeer, |
| 22 | + |
| 23 | + /// <summary>Missing retained artifact blocker.</summary> |
| 24 | + ArtifactRetention, |
| 25 | + |
| 26 | + /// <summary>Missing digest verification blocker.</summary> |
| 27 | + DigestVerification, |
| 28 | + |
| 29 | + /// <summary>Missing redaction review blocker.</summary> |
| 30 | + RedactionReview, |
| 31 | + |
| 32 | + /// <summary>Protected approval blocker.</summary> |
| 33 | + ProtectedApproval, |
| 34 | + |
| 35 | + /// <summary>Unknown blocker.</summary> |
| 36 | + Unknown |
| 37 | +} |
| 38 | + |
| 39 | +/// <summary> |
| 40 | +/// Describes one commercial evidence execution blocker. |
| 41 | +/// </summary> |
| 42 | +public sealed class SigtranCommercialEvidenceExecutionBlocker |
| 43 | +{ |
| 44 | + /// <summary>Creates a commercial evidence execution blocker.</summary> |
| 45 | + /// <param name="code">The stable blocker code.</param> |
| 46 | + /// <param name="kind">The blocker kind.</param> |
| 47 | + /// <param name="retryable">Whether the blocker can be retried after correction.</param> |
| 48 | + /// <param name="summary">The blocker summary.</param> |
| 49 | + public SigtranCommercialEvidenceExecutionBlocker( |
| 50 | + string code, |
| 51 | + SigtranCommercialEvidenceExecutionBlockerKind kind, |
| 52 | + bool retryable, |
| 53 | + string summary) |
| 54 | + { |
| 55 | + Code = string.IsNullOrWhiteSpace(code) ? throw new ArgumentException("Blocker code is required.", nameof(code)) : code; |
| 56 | + Kind = kind; |
| 57 | + Retryable = retryable; |
| 58 | + Summary = string.IsNullOrWhiteSpace(summary) ? throw new ArgumentException("Blocker summary is required.", nameof(summary)) : summary; |
| 59 | + } |
| 60 | + |
| 61 | + /// <summary>The stable blocker code.</summary> |
| 62 | + public string Code { get; } |
| 63 | + |
| 64 | + /// <summary>The blocker kind.</summary> |
| 65 | + public SigtranCommercialEvidenceExecutionBlockerKind Kind { get; } |
| 66 | + |
| 67 | + /// <summary>Whether the blocker can be retried after correction.</summary> |
| 68 | + public bool Retryable { get; } |
| 69 | + |
| 70 | + /// <summary>The blocker summary.</summary> |
| 71 | + public string Summary { get; } |
| 72 | +} |
| 73 | + |
| 74 | +/// <summary> |
| 75 | +/// Describes the commercial evidence execution blocker classifier. |
| 76 | +/// </summary> |
| 77 | +public sealed class SigtranCommercialEvidenceExecutionBlockerClassifier |
| 78 | +{ |
| 79 | + /// <summary>Creates a commercial evidence execution blocker classifier.</summary> |
| 80 | + /// <param name="knownBlockers">The known blocker definitions.</param> |
| 81 | + public SigtranCommercialEvidenceExecutionBlockerClassifier(IReadOnlyList<SigtranCommercialEvidenceExecutionBlocker> knownBlockers) |
| 82 | + { |
| 83 | + ArgumentNullException.ThrowIfNull(knownBlockers); |
| 84 | + KnownBlockers = knownBlockers.Count == 0 ? throw new ArgumentException("At least one blocker is required.", nameof(knownBlockers)) : knownBlockers.ToArray(); |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary>The known blocker definitions.</summary> |
| 88 | + public IReadOnlyList<SigtranCommercialEvidenceExecutionBlocker> KnownBlockers { get; } |
| 89 | + |
| 90 | + /// <summary>Whether blocker codes are unique.</summary> |
| 91 | + public bool HasUniqueCodes => KnownBlockers.Select(static blocker => blocker.Code).Distinct(StringComparer.OrdinalIgnoreCase).Count() == KnownBlockers.Count; |
| 92 | + |
| 93 | + /// <summary>Whether the classifier covers operational blocker kinds expected during execution.</summary> |
| 94 | + public bool CoversOperationalKinds => RequiredKinds.All(kind => KnownBlockers.Any(blocker => blocker.Kind == kind)); |
| 95 | + |
| 96 | + /// <summary>Whether the classifier is ready for execution failure handling.</summary> |
| 97 | + public bool IsReady => HasUniqueCodes |
| 98 | + && CoversOperationalKinds; |
| 99 | + |
| 100 | + /// <summary>Classifies a blocker code.</summary> |
| 101 | + /// <param name="code">The blocker code.</param> |
| 102 | + /// <returns>The matching blocker definition, or an unknown blocker.</returns> |
| 103 | + public SigtranCommercialEvidenceExecutionBlocker Classify(string code) |
| 104 | + { |
| 105 | + if (string.IsNullOrWhiteSpace(code)) |
| 106 | + { |
| 107 | + throw new ArgumentException("Blocker code is required.", nameof(code)); |
| 108 | + } |
| 109 | + |
| 110 | + return KnownBlockers.FirstOrDefault(blocker => string.Equals(blocker.Code, code, StringComparison.OrdinalIgnoreCase)) |
| 111 | + ?? new(code, SigtranCommercialEvidenceExecutionBlockerKind.Unknown, retryable: false, "Unknown blocker requires manual triage."); |
| 112 | + } |
| 113 | + |
| 114 | + /// <summary>Formats a compact blocker classifier summary.</summary> |
| 115 | + /// <returns>The blocker classifier summary.</returns> |
| 116 | + public string Describe() |
| 117 | + { |
| 118 | + return $"commercialEvidenceBlockerClassifierReady={IsReady} blockers={KnownBlockers.Count}"; |
| 119 | + } |
| 120 | + |
| 121 | + private static readonly SigtranCommercialEvidenceExecutionBlockerKind[] RequiredKinds = |
| 122 | + [ |
| 123 | + SigtranCommercialEvidenceExecutionBlockerKind.ReadinessPreflight, |
| 124 | + SigtranCommercialEvidenceExecutionBlockerKind.Environment, |
| 125 | + SigtranCommercialEvidenceExecutionBlockerKind.CommandFailure, |
| 126 | + SigtranCommercialEvidenceExecutionBlockerKind.NativeSctp, |
| 127 | + SigtranCommercialEvidenceExecutionBlockerKind.ExternalPeer, |
| 128 | + SigtranCommercialEvidenceExecutionBlockerKind.ArtifactRetention, |
| 129 | + SigtranCommercialEvidenceExecutionBlockerKind.DigestVerification, |
| 130 | + SigtranCommercialEvidenceExecutionBlockerKind.RedactionReview, |
| 131 | + SigtranCommercialEvidenceExecutionBlockerKind.ProtectedApproval |
| 132 | + ]; |
| 133 | +} |
| 134 | + |
| 135 | +/// <summary> |
| 136 | +/// Provides commercial evidence execution blocker classifier helpers. |
| 137 | +/// </summary> |
| 138 | +public static class SigtranCommercialEvidenceExecutionBlockers |
| 139 | +{ |
| 140 | + /// <summary>Creates the default commercial evidence execution blocker classifier.</summary> |
| 141 | + /// <returns>The default blocker classifier.</returns> |
| 142 | + public static SigtranCommercialEvidenceExecutionBlockerClassifier CreateDefault() |
| 143 | + { |
| 144 | + return new( |
| 145 | + [ |
| 146 | + new("preflight-not-ready", SigtranCommercialEvidenceExecutionBlockerKind.ReadinessPreflight, false, "Readiness preflight failed before execution."), |
| 147 | + new("environment-missing", SigtranCommercialEvidenceExecutionBlockerKind.Environment, true, "Required execution environment variable is missing."), |
| 148 | + new("environment-mismatch", SigtranCommercialEvidenceExecutionBlockerKind.Environment, true, "Execution environment variable does not match the locked run."), |
| 149 | + new("command-failed", SigtranCommercialEvidenceExecutionBlockerKind.CommandFailure, true, "Execution command failed and needs log review."), |
| 150 | + new("native-sctp-unavailable", SigtranCommercialEvidenceExecutionBlockerKind.NativeSctp, false, "Host does not provide usable native SCTP support."), |
| 151 | + new("external-peer-unavailable", SigtranCommercialEvidenceExecutionBlockerKind.ExternalPeer, true, "External SIGTRAN peer is unavailable or unreachable."), |
| 152 | + new("artifact-missing", SigtranCommercialEvidenceExecutionBlockerKind.ArtifactRetention, true, "Required retained artifact is missing."), |
| 153 | + new("digest-missing", SigtranCommercialEvidenceExecutionBlockerKind.DigestVerification, true, "Required artifact digest is missing."), |
| 154 | + new("redaction-review-missing", SigtranCommercialEvidenceExecutionBlockerKind.RedactionReview, true, "Required redaction review is missing."), |
| 155 | + new("protected-approval-missing", SigtranCommercialEvidenceExecutionBlockerKind.ProtectedApproval, false, "Protected approval is required before execution can continue.") |
| 156 | + ]); |
| 157 | + } |
| 158 | +} |
0 commit comments