using System; using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using StellaOps.Signals.Models; namespace StellaOps.Signals.Services; /// /// Placeholder events publisher; replace with real bus integration when contracts are finalized. /// internal sealed class InMemoryEventsPublisher : IEventsPublisher { private readonly ILogger logger; private readonly ReachabilityFactEventBuilder eventBuilder; private static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web) { WriteIndented = false, DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull }; public InMemoryEventsPublisher(ILogger logger, ReachabilityFactEventBuilder eventBuilder) { this.logger = logger; this.eventBuilder = eventBuilder ?? throw new ArgumentNullException(nameof(eventBuilder)); } public Task PublishFactUpdatedAsync(ReachabilityFactDocument fact, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(fact); var envelope = eventBuilder.Build(fact); var json = JsonSerializer.Serialize(envelope, SerializerOptions); logger.LogInformation(json); return Task.CompletedTask; } }