|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes a publication handoff for an approved commercial evidence run. |
| 5 | +/// </summary> |
| 6 | +public sealed class SigtranCommercialEvidencePublicationHandoff |
| 7 | +{ |
| 8 | + /// <summary>Creates an approved commercial evidence publication handoff.</summary> |
| 9 | + /// <param name="promotionPackage">The approved run promotion package.</param> |
| 10 | + /// <param name="channel">The requested publication channel.</param> |
| 11 | + /// <param name="requestedBy">The requester identity.</param> |
| 12 | + /// <param name="createdAtUtc">The UTC handoff creation time.</param> |
| 13 | + /// <param name="publishRequested">Whether publication was explicitly requested.</param> |
| 14 | + public SigtranCommercialEvidencePublicationHandoff( |
| 15 | + SigtranCommercialEvidenceApprovedRunPromotionPackage promotionPackage, |
| 16 | + SigtranPublishChannel channel, |
| 17 | + string requestedBy, |
| 18 | + DateTimeOffset createdAtUtc, |
| 19 | + bool publishRequested) |
| 20 | + { |
| 21 | + PromotionPackage = promotionPackage ?? throw new ArgumentNullException(nameof(promotionPackage)); |
| 22 | + Channel = channel ?? throw new ArgumentNullException(nameof(channel)); |
| 23 | + RequestedBy = string.IsNullOrWhiteSpace(requestedBy) ? throw new ArgumentException("Requester is required.", nameof(requestedBy)) : requestedBy; |
| 24 | + CreatedAtUtc = createdAtUtc.Offset == TimeSpan.Zero ? createdAtUtc : createdAtUtc.ToUniversalTime(); |
| 25 | + PublishRequested = publishRequested; |
| 26 | + } |
| 27 | + |
| 28 | + /// <summary>The approved run promotion package.</summary> |
| 29 | + public SigtranCommercialEvidenceApprovedRunPromotionPackage PromotionPackage { get; } |
| 30 | + |
| 31 | + /// <summary>The requested publication channel.</summary> |
| 32 | + public SigtranPublishChannel Channel { get; } |
| 33 | + |
| 34 | + /// <summary>The requester identity.</summary> |
| 35 | + public string RequestedBy { get; } |
| 36 | + |
| 37 | + /// <summary>The UTC handoff creation time.</summary> |
| 38 | + public DateTimeOffset CreatedAtUtc { get; } |
| 39 | + |
| 40 | + /// <summary>Whether publication was explicitly requested.</summary> |
| 41 | + public bool PublishRequested { get; } |
| 42 | + |
| 43 | + /// <summary>The package version covered by the handoff.</summary> |
| 44 | + public string PackageVersion => PromotionPackage.ApprovalReport.Manifest.Checklist.Target.PackageVersion; |
| 45 | + |
| 46 | + /// <summary>Whether the handoff creation time is normalized to UTC.</summary> |
| 47 | + public bool HasUtcCreationTime => CreatedAtUtc.Offset == TimeSpan.Zero; |
| 48 | + |
| 49 | + /// <summary>Whether the selected publication channel accepts the package version.</summary> |
| 50 | + public bool ChannelAcceptsPackageVersion => Channel.AcceptsVersion(PackageVersion); |
| 51 | + |
| 52 | + /// <summary>Whether the selected publication channel requires commercial readiness.</summary> |
| 53 | + public bool RequiresCommercialReadiness => Channel.RequiresCommercialReadiness; |
| 54 | + |
| 55 | + /// <summary>Whether the handoff is ready for publication gate evaluation.</summary> |
| 56 | + public bool IsReadyForPublicationGate => PromotionPackage.IsReady |
| 57 | + && PublishRequested |
| 58 | + && HasUtcCreationTime |
| 59 | + && ChannelAcceptsPackageVersion; |
| 60 | + |
| 61 | + /// <summary>Formats a compact publication handoff summary.</summary> |
| 62 | + /// <returns>The publication handoff summary.</returns> |
| 63 | + public string Describe() |
| 64 | + { |
| 65 | + return $"commercialEvidencePublicationHandoffReady={IsReadyForPublicationGate} channel={Channel.FeedName} version={PackageVersion}"; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +/// <summary> |
| 70 | +/// Provides approved commercial evidence publication handoff helpers. |
| 71 | +/// </summary> |
| 72 | +public static class SigtranCommercialEvidencePublicationHandoffs |
| 73 | +{ |
| 74 | + /// <summary>Creates a publication handoff for an approved commercial evidence run.</summary> |
| 75 | + /// <param name="promotionPackage">The approved run promotion package.</param> |
| 76 | + /// <param name="channelKind">The requested publication channel kind.</param> |
| 77 | + /// <param name="requestedBy">The requester identity.</param> |
| 78 | + /// <param name="createdAtUtc">The UTC handoff creation time.</param> |
| 79 | + /// <param name="publishRequested">Whether publication was explicitly requested.</param> |
| 80 | + /// <returns>The approved commercial evidence publication handoff.</returns> |
| 81 | + public static SigtranCommercialEvidencePublicationHandoff Create( |
| 82 | + SigtranCommercialEvidenceApprovedRunPromotionPackage promotionPackage, |
| 83 | + SigtranPublishChannelKind channelKind, |
| 84 | + string requestedBy, |
| 85 | + DateTimeOffset createdAtUtc, |
| 86 | + bool publishRequested = true) |
| 87 | + { |
| 88 | + SigtranPublishChannel channel = SigtranPublishChannels.GetChannels().First(item => item.Kind == channelKind); |
| 89 | + return new(promotionPackage, channel, requestedBy, createdAtUtc, publishRequested); |
| 90 | + } |
| 91 | +} |
0 commit comments