using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
/// Bounded, secret-free evidence from one node's applied data connection.
/// Nullable measures mean that evidence is unavailable, rather than zero activity.
public sealed record DataConnectionDiagnosticsSnapshot(
string ConnectionId,
long Revision,
string State,
string? SelectedEndpoint,
ServingIdentity? Serving,
int ActiveStreams,
int ActiveCalls,
long ScopeVersion,
string ArtifactRevision,
DateTime AsOfUtc,
DateTime? LastSampleAtUtc = null,
DateTime? MetadataLeaseExpiresAtUtc = null,
int? SourceCount = null,
int? RegistrationCount = null,
long? ResetCount = null,
long? OverflowCount = null,
long? WriteSucceededCount = null,
long? WriteRejectedCount = null,
long? WriteUnknownCount = null,
int? ProtocolMajor = null,
int? ProtocolMinor = null,
DateTime? LastVerifiedAtUtc = null,
long? WriteFailedCount = null,
long? WriteUnconfirmedCount = null,
TimeSpan? SampleAgeUpperBound = null,
long? CoalescedCount = null,
long? CompactFrameCount = null,
long? FallbackFrameCount = null,
long? SerializedValueFrameBytes = null,
string? AccountingInstanceId = null,
// X0 tolerant reader: operation bits this connection row was authored with that this node does not implement and
// dropped (None = nothing dropped; null = from an older sender), and how many of its mappings had bits dropped.
DataOperations? DroppedUnknownOperations = null,
int? MappingsWithDroppedOperations = null,
// H4 consumer-side history evidence: the features the last capability handshake negotiated (None = v1 behaviour), the
// history variants and aggregate count the origin advertised to this caller, projected HistoryRead results by status
// class (per node, as answered to local OPC UA clients) and the remote continuations held in local sessions.
DataFeatures? NegotiatedFeatures = null,
IReadOnlyList? HistoryVariants = null,
int? HistoryAggregateCount = null,
long? HistoryReadsGood = null,
long? HistoryReadsUncertain = null,
long? HistoryReadsBad = null,
int? OpenRemoteContinuations = null,
// A4 consumer-side imported-condition evidence (null = no condition-bearing mapping on this connection, or an older sender).
ConsumerConditionDiagnostics? Conditions = null);
/// A4: one condition-bearing mapping of a consumer connection's condition stream.
/// The mapping.
/// Pending | Snapshotting | Complete | Unavailable | ConditionCapacity.
/// The last count the origin reported or listed for it (a snapshot total, or the committed set).
/// The mapping's MaxConditions.
/// The origin's last refusal status for its item or root (null when not refused).
public sealed record ConditionMappingDiagnostics(string MappingId, string Status, int Observed, int Limit, string? Refusal = null);
/// A4: consumer evidence of one connection's imported conditions (plan ยง6 "AdminUI").
/// idle (no event subscriber) | connecting | snapshotting | live.
/// When the connection's last snapshot barrier passed (null: none since start).
/// Imported conditions this node holds for the connection.
/// Of those, how many carry state_known = false (never shown known-inactive).
/// RefreshRequired requests made for the connection since start (explicit, plus each removal batch).
/// Condition streams that ended and re-snapshotted since start.
/// Mappings reset to ConditionCapacity since start.
/// Per mapping: status, observed count vs limit, refusal.
/// Imported conditions charged against this node's host caps (every connection).
/// The node-wide condition cap implied by MaxImportedConditionNodes/Bytes.
public sealed record ConsumerConditionDiagnostics(string StreamState, DateTime? SnapshotAtUtc, int Materialised, int StateUnknown,
long RefreshRequired, long Resyncs, long CapacityRejections, IReadOnlyList Mappings,
long ChargedConditions, long HostConditionLimit, ConditionMethodCounts Methods);
/// A4: remote condition method calls by outcome class (from DataWriteState).
public sealed record ConditionMethodCounts(long Succeeded, long Rejected, long Failed, long Unknown);
/// A4: origin-side evidence of the root-scoped condition items this node serves to peers.
/// Open condition items (all peers).
/// The largest current listing among the open items (their last snapshot's total).
/// That item's MaxConditions limit (0 when no item is open).
/// When an item last took a snapshot (null: none since start).
/// Items re-snapshotted after a hub reader reset since start.
/// Item snapshots refused as over the item's limit since start.
/// Native conditions whose initial state was never signalled (served state_known = false);
/// null when the node has no condition hub.
/// Remote condition method calls served, by outcome class.
public sealed record OriginConditionDiagnostics(int OpenItems, int LargestListing, int ListingLimit, DateTime? LastSnapshotAtUtc,
long Resyncs, long CapacityRejections, int? UnsignalledConditions, ConditionMethodCounts Methods);
/// H4 origin-side remote-history evidence for one node (what it serves to peers over data connections).
/// The node has a historian backend and can serve remote history.
/// Live peer history sessions.
/// Origin continuations (page cursors and chunk remainders) held for peers.
/// Remote history items answered Good since process start.
/// Remote history items answered Uncertain since process start.
/// Remote history items answered Bad (including refusals) since process start.
///
/// True while no peer has called this node since start: the origin data services are created on the first peer call, so
/// the zeros are "no peer traffic yet", not missing evidence. False once they run. Default false, so a payload without the
/// member (Akka's JSON serializer fills a missing constructor argument with the CLR default) never claims it.
///
public sealed record OriginHistoryDiagnostics(bool Available, int Sessions, int OpenContinuations, long ReadsGood,
long ReadsUncertain, long ReadsBad, bool NoPeerTrafficYet = false);