using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health;
using ZB.MOM.WW.ScadaBridge.Commons.Types;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
namespace ZB.MOM.WW.ScadaBridge.HealthMonitoring;
///
/// Interface for site-side health metric collection.
/// Consumed by Site Runtime actors to report errors, and by DCL to report connection health.
///
public interface ISiteHealthCollector
{
///
/// Increments the script error count.
///
void IncrementScriptError();
///
/// Increments the alarm error count.
///
void IncrementAlarmError();
///
/// Increments the dead letter count.
///
void IncrementDeadLetter();
///
/// Audit Log (#23) Bundle G — increment the per-interval count of
/// FallbackAuditWriter primary failures. Bridged from the
/// IAuditWriteFailureCounter binding registered via
/// AddAuditLogHealthMetricsBridge().
///
void IncrementSiteAuditWriteFailures();
///
/// Audit Log (#23) M5 Bundle C — increment the per-interval count of
/// payload-filter redactor over-redactions (header / body / SQL
/// parameter stage throws routed to the
/// <redacted: redactor error> marker). Bridged from the
/// IAuditRedactionFailureCounter binding registered via
/// AddAuditLogHealthMetricsBridge().
///
void IncrementAuditRedactionFailure();
///
/// Audit Log (#23) M6 Bundle E (T6) — replace the latest site-local
/// audit-queue backlog snapshot (pending count, oldest pending row,
/// on-disk file bytes) used by the next call.
/// Refreshed periodically by the SiteAuditBacklogReporter hosted
/// service so each report carries a recent point-in-time view of the
/// site→central drain health.
///
/// The audit backlog snapshot.
void UpdateSiteAuditBacklog(SiteAuditBacklogSnapshot snapshot);
///
/// Updates the health status for a data connection.
///
/// The name of the connection.
/// The connection health status.
void UpdateConnectionHealth(string connectionName, ConnectionHealth health);
///
/// Removes a connection from health tracking.
///
/// The name of the connection.
void RemoveConnection(string connectionName);
///
/// Updates tag resolution metrics for a connection.
///
/// The name of the connection.
/// Total number of subscribed tags.
/// Number of successfully resolved tags.
void UpdateTagResolution(string connectionName, int totalSubscribed, int successfullyResolved);
///
/// Updates the endpoint for a connection.
///
/// The name of the connection.
/// The connection endpoint.
void UpdateConnectionEndpoint(string connectionName, string endpoint);
///
/// Updates tag quality metrics for a connection.
///
/// The name of the connection.
/// Number of good quality tags.
/// Number of bad quality tags.
/// Number of uncertain quality tags.
void UpdateTagQuality(string connectionName, int good, int bad, int uncertain);
///
/// Sets the store-and-forward buffer depths for all categories.
///
/// Dictionary mapping category names to their buffer depths.
void SetStoreAndForwardDepths(IReadOnlyDictionary depths);
///
/// Sets the counts of instances in each state.
///
/// Number of deployed instances.
/// Number of enabled instances.
/// Number of disabled instances.
void SetInstanceCounts(int deployed, int enabled, int disabled);
///
/// Sets the count of parked messages.
///
/// The number of parked messages.
void SetParkedMessageCount(int count);
///
/// Sets the hostname of this node.
///
/// The node hostname.
void SetNodeHostname(string hostname);
///
/// Sets the list of cluster nodes.
///
/// The list of cluster node statuses.
void SetClusterNodes(IReadOnlyList nodes);
///
/// Sets whether this node is the active node in the cluster.
///
/// True if this node is active, false otherwise.
void SetActiveNode(bool isActive);
///
/// Gets whether this node is the active node in the cluster.
///
bool IsActiveNode { get; }
///
/// Collects and returns a health report for a site.
///
/// The site identifier.
/// A health report for the specified site.
SiteHealthReport CollectReport(string siteId);
///
/// HealthMonitoring-017: atomically add back the given per-interval error
/// counts into the collector's accumulators. Called by the report sender
/// when transport delivery of a freshly-collected report fails, so the
/// counts that already drained roll forward
/// into the next report rather than being silently lost. Concurrent
/// increments arriving between the failed Send and this restore are
/// preserved — Interlocked.Add sums correctly with them. The
/// default interface implementation is a no-op so existing test fakes
/// (the only implementations outside )
/// continue to compile without per-fake updates; production callers see
/// the real behaviour via the concrete class.
///
/// Script error count to add back.
/// Alarm evaluation error count to add back.
/// Dead letter count to add back.
/// Site audit write failure count to add back.
/// Audit redaction failure count to add back.
void AddIntervalCounters(
int scriptErrors,
int alarmErrors,
int deadLetters,
int siteAuditWriteFailures,
int auditRedactionFailures)
{
// Default no-op so test fakes do not need to be updated. The real
// SiteHealthCollector overrides this with the Interlocked.Add restore.
}
}