43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace StellaOps.PolicyAuthoritySignals.Contracts;
|
|
|
|
public sealed record PolicyContract
|
|
{
|
|
private string _policyId = string.Empty;
|
|
|
|
[JsonPropertyName("policyId")]
|
|
public string PolicyId
|
|
{
|
|
get => _policyId;
|
|
init => _policyId = RequireNonEmpty(value, nameof(PolicyId));
|
|
}
|
|
|
|
[JsonPropertyName("version")]
|
|
public string Version { get; init; } = "0.1-draft";
|
|
|
|
[JsonPropertyName("rulesHash")]
|
|
public string? RulesHash { get; init; }
|
|
|
|
public PolicyContract(string policyId, string? version = null, string? rulesHash = null)
|
|
{
|
|
PolicyId = policyId;
|
|
if (!string.IsNullOrWhiteSpace(version))
|
|
{
|
|
Version = version;
|
|
}
|
|
|
|
RulesHash = rulesHash;
|
|
}
|
|
|
|
private static string RequireNonEmpty(string value, string paramName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
throw new ArgumentException("Value cannot be null or whitespace.", paramName);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
}
|