using System.Text.Json.Serialization; using StellaOps.Policy.RiskProfile.Lifecycle; namespace StellaOps.Policy.Engine.Events; /// /// Base class for profile lifecycle events. /// public abstract record ProfileEvent( [property: JsonPropertyName("event_id")] string EventId, [property: JsonPropertyName("event_type")] ProfileEventType EventType, [property: JsonPropertyName("profile_id")] string ProfileId, [property: JsonPropertyName("profile_version")] string ProfileVersion, [property: JsonPropertyName("timestamp")] DateTimeOffset Timestamp, [property: JsonPropertyName("actor")] string? Actor, [property: JsonPropertyName("correlation_id")] string? CorrelationId); /// /// Type of profile event. /// [JsonConverter(typeof(JsonStringEnumConverter))] public enum ProfileEventType { [JsonPropertyName("profile_created")] ProfileCreated, [JsonPropertyName("profile_published")] ProfilePublished, [JsonPropertyName("profile_activated")] ProfileActivated, [JsonPropertyName("profile_deprecated")] ProfileDeprecated, [JsonPropertyName("profile_archived")] ProfileArchived, [JsonPropertyName("severity_threshold_changed")] SeverityThresholdChanged, [JsonPropertyName("weight_changed")] WeightChanged, [JsonPropertyName("override_added")] OverrideAdded, [JsonPropertyName("override_removed")] OverrideRemoved, [JsonPropertyName("scope_attached")] ScopeAttached, [JsonPropertyName("scope_detached")] ScopeDetached } /// /// Event emitted when a profile is created. /// public sealed record ProfileCreatedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId, [property: JsonPropertyName("content_hash")] string ContentHash, [property: JsonPropertyName("description")] string? Description) : ProfileEvent(EventId, ProfileEventType.ProfileCreated, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Event emitted when a profile is published/activated. /// public sealed record ProfilePublishedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId, [property: JsonPropertyName("content_hash")] string ContentHash, [property: JsonPropertyName("previous_active_version")] string? PreviousActiveVersion) : ProfileEvent(EventId, ProfileEventType.ProfilePublished, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Event emitted when a profile is deprecated. /// public sealed record ProfileDeprecatedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId, [property: JsonPropertyName("reason")] string? Reason, [property: JsonPropertyName("successor_version")] string? SuccessorVersion) : ProfileEvent(EventId, ProfileEventType.ProfileDeprecated, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Event emitted when a profile is archived. /// public sealed record ProfileArchivedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId) : ProfileEvent(EventId, ProfileEventType.ProfileArchived, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Event emitted when severity thresholds change. /// public sealed record SeverityThresholdChangedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId, [property: JsonPropertyName("changes")] IReadOnlyList Changes) : ProfileEvent(EventId, ProfileEventType.SeverityThresholdChanged, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Details of a threshold change. /// public sealed record ThresholdChange( [property: JsonPropertyName("threshold_name")] string ThresholdName, [property: JsonPropertyName("old_value")] double? OldValue, [property: JsonPropertyName("new_value")] double? NewValue); /// /// Event emitted when weights change. /// public sealed record WeightChangedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId, [property: JsonPropertyName("signal_name")] string SignalName, [property: JsonPropertyName("old_weight")] double OldWeight, [property: JsonPropertyName("new_weight")] double NewWeight) : ProfileEvent(EventId, ProfileEventType.WeightChanged, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Event emitted when a scope is attached. /// public sealed record ScopeAttachedEvent( string EventId, string ProfileId, string ProfileVersion, DateTimeOffset Timestamp, string? Actor, string? CorrelationId, [property: JsonPropertyName("scope_type")] string ScopeType, [property: JsonPropertyName("scope_id")] string ScopeId, [property: JsonPropertyName("attachment_id")] string AttachmentId) : ProfileEvent(EventId, ProfileEventType.ScopeAttached, ProfileId, ProfileVersion, Timestamp, Actor, CorrelationId); /// /// Event subscription request. /// public sealed record EventSubscription( [property: JsonPropertyName("subscription_id")] string SubscriptionId, [property: JsonPropertyName("event_types")] IReadOnlyList EventTypes, [property: JsonPropertyName("profile_filter")] string? ProfileFilter, [property: JsonPropertyName("webhook_url")] string? WebhookUrl, [property: JsonPropertyName("created_at")] DateTimeOffset CreatedAt, [property: JsonPropertyName("created_by")] string? CreatedBy);