|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes one commercial evidence artifact intake target. |
| 5 | +/// </summary> |
| 6 | +public sealed class SigtranCommercialEvidenceArtifactIntakeTarget |
| 7 | +{ |
| 8 | + /// <summary>Creates a commercial evidence artifact intake target.</summary> |
| 9 | + /// <param name="intakeId">The stable intake identifier.</param> |
| 10 | + /// <param name="executionRun">The execution run that produced the artifacts.</param> |
| 11 | + /// <param name="reviewerName">The reviewer or automation identity performing intake.</param> |
| 12 | + /// <param name="receivedAtUtc">The UTC artifact intake time.</param> |
| 13 | + /// <param name="dossierRoot">The retained dossier root.</param> |
| 14 | + public SigtranCommercialEvidenceArtifactIntakeTarget( |
| 15 | + string intakeId, |
| 16 | + SigtranCommercialEvidenceExecutionRun executionRun, |
| 17 | + string reviewerName, |
| 18 | + DateTimeOffset receivedAtUtc, |
| 19 | + string dossierRoot) |
| 20 | + { |
| 21 | + IntakeId = string.IsNullOrWhiteSpace(intakeId) ? throw new ArgumentException("Intake identifier is required.", nameof(intakeId)) : intakeId; |
| 22 | + ExecutionRun = executionRun ?? throw new ArgumentNullException(nameof(executionRun)); |
| 23 | + ReviewerName = string.IsNullOrWhiteSpace(reviewerName) ? throw new ArgumentException("Reviewer name is required.", nameof(reviewerName)) : reviewerName; |
| 24 | + ReceivedAtUtc = receivedAtUtc.Offset == TimeSpan.Zero ? receivedAtUtc : receivedAtUtc.ToUniversalTime(); |
| 25 | + DossierRoot = string.IsNullOrWhiteSpace(dossierRoot) ? throw new ArgumentException("Dossier root is required.", nameof(dossierRoot)) : dossierRoot; |
| 26 | + } |
| 27 | + |
| 28 | + /// <summary>The stable intake identifier.</summary> |
| 29 | + public string IntakeId { get; } |
| 30 | + |
| 31 | + /// <summary>The execution run that produced the artifacts.</summary> |
| 32 | + public SigtranCommercialEvidenceExecutionRun ExecutionRun { get; } |
| 33 | + |
| 34 | + /// <summary>The reviewer or automation identity performing intake.</summary> |
| 35 | + public string ReviewerName { get; } |
| 36 | + |
| 37 | + /// <summary>The UTC artifact intake time.</summary> |
| 38 | + public DateTimeOffset ReceivedAtUtc { get; } |
| 39 | + |
| 40 | + /// <summary>The retained dossier root.</summary> |
| 41 | + public string DossierRoot { get; } |
| 42 | + |
| 43 | + /// <summary>Whether the intake identifier is stable and suitable for retained paths.</summary> |
| 44 | + public bool HasStableIntakeId => IntakeId.Length >= 8 |
| 45 | + && IntakeId.All(static c => char.IsLetterOrDigit(c) || c is '-' or '_'); |
| 46 | + |
| 47 | + /// <summary>Whether the intake timestamp is normalized to UTC.</summary> |
| 48 | + public bool HasUtcReceivedTime => ReceivedAtUtc.Offset == TimeSpan.Zero; |
| 49 | + |
| 50 | + /// <summary>Whether the dossier root is scoped under the execution run artifact root.</summary> |
| 51 | + public bool HasRunScopedDossierRoot => DossierRoot.StartsWith(ExecutionRun.RunArtifactRoot + "/dossiers/" + IntakeId, StringComparison.Ordinal); |
| 52 | + |
| 53 | + /// <summary>Whether the intake target is ready for artifact source registration.</summary> |
| 54 | + public bool IsReady => ExecutionRun.IsReady |
| 55 | + && HasStableIntakeId |
| 56 | + && HasUtcReceivedTime |
| 57 | + && HasRunScopedDossierRoot; |
| 58 | + |
| 59 | + /// <summary>Formats a compact artifact intake target summary.</summary> |
| 60 | + /// <returns>The artifact intake target summary.</returns> |
| 61 | + public string Describe() |
| 62 | + { |
| 63 | + return $"commercialEvidenceArtifactIntake={IntakeId} run={ExecutionRun.RunId} ready={IsReady}"; |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +/// <summary> |
| 68 | +/// Provides commercial evidence artifact intake target helpers. |
| 69 | +/// </summary> |
| 70 | +public static class SigtranCommercialEvidenceArtifactIntakes |
| 71 | +{ |
| 72 | + /// <summary>Creates a default artifact intake target for an execution run.</summary> |
| 73 | + /// <param name="executionRun">The execution run that produced the artifacts.</param> |
| 74 | + /// <param name="intakeId">The stable intake identifier.</param> |
| 75 | + /// <param name="reviewerName">The reviewer or automation identity performing intake.</param> |
| 76 | + /// <param name="receivedAtUtc">The UTC artifact intake time.</param> |
| 77 | + /// <returns>The artifact intake target.</returns> |
| 78 | + public static SigtranCommercialEvidenceArtifactIntakeTarget CreateDefault( |
| 79 | + SigtranCommercialEvidenceExecutionRun executionRun, |
| 80 | + string intakeId, |
| 81 | + string reviewerName, |
| 82 | + DateTimeOffset receivedAtUtc) |
| 83 | + { |
| 84 | + ArgumentNullException.ThrowIfNull(executionRun); |
| 85 | + |
| 86 | + return new( |
| 87 | + intakeId, |
| 88 | + executionRun, |
| 89 | + reviewerName, |
| 90 | + receivedAtUtc, |
| 91 | + $"{executionRun.RunArtifactRoot}/dossiers/{intakeId}"); |
| 92 | + } |
| 93 | +} |
0 commit comments