using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using ZB.MOM.WW.ScadaBridge.CentralUI.Services; using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories; using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services; using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Transport; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates; using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health; using ZB.MOM.WW.ScadaBridge.Commons.Messages.Notification; using ZB.MOM.WW.ScadaBridge.Commons.Messages.Audit; using ZB.MOM.WW.ScadaBridge.Commons.Types.Audit; using ZB.MOM.WW.ScadaBridge.Commons.Types; using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums; using ZB.MOM.WW.ScadaBridge.Communication; using ZB.MOM.WW.ScadaBridge.DeploymentManager; using ZB.MOM.WW.ScadaBridge.DeploymentManager.PendingUpdates; using ZB.MOM.WW.ScadaBridge.HealthMonitoring; using ZB.MOM.WW.ScadaBridge.TemplateEngine.Services; using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening; // Disposable read-only synthetic projections. Real service constructors are resolved but never // receive an actor system or a database. Every mutation and external probe remains rejected. internal static class BatchThreeFixtures { public static void Register(IServiceCollection services) { var sites = Enumerable.Range(1, 12).Select(i => new Site($"Synthetic facility {i:00} with a deliberately long local display name", $"fixture-{i:00}") { Id = i }).ToArray(); services.AddScoped(_ => ReadOnlyFixtureProxy.WithReads(new Dictionary> { ["GetAllSitesAsync"] = _ => Task.FromResult>(sites), ["GetAllDataConnectionsAsync"] = _ => Task.FromResult>([]) })); services.AddScoped(_ => ReadOnlyFixtureProxy.WithReads(new Dictionary> { ["GetAllTemplatesAsync"] = _ => Task.FromResult>([]), ["GetTemplateStubsAsync"] = _ => Task.FromResult>([]), ["GetAreasBySiteIdAsync"] = args => Task.FromResult>(Enumerable.Range(1, 6).Select(i => new Area($"Synthetic area {i:00} with a long inspection label") { Id = (int)args[0]! * 100 + i, SiteId = (int)args[0]! }).ToArray()), ["GetTopologyInstancesAsync"] = _ => Task.FromResult>([]) })); services.AddScoped(); services.AddScoped(); services.AddSingleton(new EmptyPending()); services.AddSingleton(new SyntheticKpis()); var now = DateTimeOffset.UtcNow; SiteHealthReport Report(string id) => new(id, 1, now, new Dictionary(), new Dictionary(), 0, 0, new Dictionary(), 0, 0, 0, 0); var states = new Dictionary { ["healthy"] = new() { SiteId="healthy", IsOnline=true, LatestReport=Report("healthy"), LastReportReceivedAt=now, LastHeartbeatAt=now }, ["offline"] = new() { SiteId="offline", IsOnline=false, LatestReport=Report("offline"), LastReportReceivedAt=now.AddMinutes(-8), LastHeartbeatAt=now.AddMinutes(-8) }, ["warning"] = new() { SiteId="warning", IsOnline=true, IsMetricsStale=true, LatestReport=Report("warning"), LastReportReceivedAt=now.AddMinutes(-4), LastHeartbeatAt=now }, ["unknown"] = new() { SiteId="unknown", IsOnline=true, LastHeartbeatAt=now } }; services.AddSingleton(ReadOnlyFixtureProxy.WithReads(new Dictionary> { ["GetAllSiteStates"] = _ => states })); services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads()); services.AddSingleton(Options.Create(new HealthMonitoringOptions())); services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads()); services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads()); services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads()); services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads()); services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads()); services.AddSingleton(new CommunicationService(Options.Create(new CommunicationOptions()), NullLogger.Instance)); services.AddSingleton(new OperationLockManager()); services.AddSingleton(Options.Create(new DeploymentManagerOptions())); services.AddSingleton(Options.Create(new CommunicationOptions())); services.AddSingleton>(NullLogger.Instance); services.AddScoped(); services.AddScoped(); services.AddSingleton(new DeploymentStatusNotifier(NullLogger.Instance)); services.AddScoped(); services.AddScoped(); services.AddScoped(); } private sealed class EmptyPending : IPendingUpdatesCache { public event Action? Invalidated { add { } remove { } } public Task GetAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new PendingUpdatesSnapshot(DateTimeOffset.UtcNow, [])); } private sealed class SyntheticKpis : IKpiSnapshotCache { public Task GetNotificationKpisAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new NotificationKpiResponse("local", true, null, 2, 0, 0, 4, null)); public Task GetPerSiteNotificationKpisAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new PerSiteNotificationKpiResponse("local", true, null, [])); public Task GetPerNodeNotificationKpisAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new PerNodeNotificationKpiResponse("local", true, null, [])); public Task GetSiteCallKpisAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new SiteCallKpiResponse("local", true, null, 0, 0, 0, 2, null, 0)); public Task GetPerNodeSiteCallKpisAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new PerNodeSiteCallKpiResponse("local", true, null, [])); public Task GetAuditKpiSnapshotAsync(bool forceRefresh=false, CancellationToken cancellationToken=default) => Task.FromResult(new AuditLogKpiSnapshot(3, 0, 0, DateTime.UtcNow)); } }