using Opc.Ua;
namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters;
///
/// Abstracts the OPC UA session for read, write, browse, history, and subscription operations.
///
internal interface ISessionAdapter : IDisposable
{
///
/// Gets a value indicating whether the underlying OPC UA session is currently usable for client operations.
///
bool Connected { get; }
///
/// Gets the server-assigned session identifier for diagnostics and failover reporting.
///
string SessionId { get; }
///
/// Gets the friendly session name presented to the OPC UA server.
///
string SessionName { get; }
///
/// Gets the active endpoint URL that this adapter is connected to.
///
string EndpointUrl { get; }
///
/// Gets the server name reported by the connected OPC UA endpoint.
///
string ServerName { get; }
///
/// Gets the negotiated OPC UA message security mode for the session.
///
string SecurityMode { get; }
///
/// Gets the negotiated OPC UA security policy URI for the session.
///
string SecurityPolicyUri { get; }
///
/// Gets the namespace table used to resolve expanded node identifiers returned by browse operations.
///
NamespaceTable NamespaceUris { get; }
///
/// Registers a keep-alive callback. The callback receives true when the session is healthy, false on failure.
///
/// The callback used by higher-level clients to trigger reconnect or failover behavior.
void RegisterKeepAliveHandler(Action callback);
///
/// Reads the current value for a node from the connected OPC UA server.
///
/// The node whose current runtime value should be read.
/// The cancellation token that aborts the server read if the client cancels the request.
/// The current data value read from the server.
Task ReadValueAsync(NodeId nodeId, CancellationToken ct = default);
///
/// Writes a typed value to a node on the connected OPC UA server.
///
/// The node whose value should be updated.
/// The typed OPC UA data value to write to the server.
/// The cancellation token that aborts the write if the client cancels the request.
/// The status code returned by the server for the write operation.
Task WriteValueAsync(NodeId nodeId, DataValue value, CancellationToken ct = default);
///
/// Browses forward hierarchical references from the given node.
/// Returns (continuationPoint, references).
///
/// The starting node for the hierarchical browse.
/// The node classes that should be returned to the caller.
/// The cancellation token that aborts the browse request.
/// A continuation point (or null when complete) and the references found.
Task<(byte[]? ContinuationPoint, ReferenceDescriptionCollection References)> BrowseAsync(
NodeId nodeId, uint nodeClassMask = 0, CancellationToken ct = default);
///
/// Continues a browse from a continuation point.
///
/// The continuation token returned by a prior browse result page.
/// The cancellation token that aborts the browse-next request.
/// The next continuation point (or null when exhausted) and the additional references.
Task<(byte[]? ContinuationPoint, ReferenceDescriptionCollection References)> BrowseNextAsync(
byte[] continuationPoint, CancellationToken ct = default);
///
/// Checks whether a node has any forward hierarchical child references.
///
/// The node to inspect for child objects or variables.
/// The cancellation token that aborts the child lookup.
/// true when the node has at least one forward hierarchical child reference; otherwise false.
Task HasChildrenAsync(NodeId nodeId, CancellationToken ct = default);
///
/// Reads raw historical data.
///
/// The historized node whose raw samples should be retrieved.
/// The inclusive start of the requested history window.
/// The inclusive end of the requested history window.
/// The maximum number of raw samples to return to the client.
/// The cancellation token that aborts the history read.
/// The raw historical data values for the requested window.
Task> HistoryReadRawAsync(NodeId nodeId, DateTime startTime, DateTime endTime,
int maxValues, CancellationToken ct = default);
///
/// Reads modified-value history (Part 11, IsReadModified = true): the prior values and modification info
/// the server recorded for every HistoryUpdate in the window, following continuation points.
///
/// The historized node.
/// Window start.
/// Window end.
/// The maximum number of entries to return.
/// The cancellation token.
/// The modification entries in server order.
Task> HistoryReadModifiedAsync(NodeId nodeId, DateTime startTime,
DateTime endTime, int maxValues, CancellationToken ct = default) =>
throw new NotSupportedException("This session adapter does not support modified-value history reads.");
///
/// Sends a HistoryUpdate request for the supplied details.
///
/// The history update details.
/// The cancellation token that aborts the call.
/// The overall service result and per-item status codes.
Task HistoryUpdateAsync(HistoryUpdateDetails details, CancellationToken ct = default)
=> throw new NotSupportedException("HistoryUpdate is not supported by this session adapter.");
///
/// Reads processed/aggregate historical data.
///
/// The historized node whose processed values should be retrieved.
/// The inclusive start of the requested processed-history window.
/// The inclusive end of the requested processed-history window.
/// The OPC UA aggregate function to evaluate over the history window.
/// The processing interval, in milliseconds, for each aggregate bucket.
/// The cancellation token that aborts the aggregate history read.
/// The processed/aggregate data values for the requested window.
Task> HistoryReadAggregateAsync(NodeId nodeId, DateTime startTime, DateTime endTime,
NodeId aggregateId, double intervalMs, CancellationToken ct = default);
///
/// Creates a subscription adapter for this session.
///
/// The requested publishing interval for monitored items on the new subscription.
/// The cancellation token that aborts subscription creation.
/// The newly created subscription adapter.
Task CreateSubscriptionAsync(int publishingIntervalMs, CancellationToken ct = default);
///
/// Calls an OPC UA method node with the provided input arguments.
///
/// The object node that owns the target method.
/// The method node to invoke.
/// The ordered input arguments supplied to the server method call.
/// The cancellation token that aborts the method invocation.
/// The output arguments returned by the method call.
Task?> CallMethodAsync(NodeId objectId, NodeId methodId, object[] inputArguments, CancellationToken ct = default);
///
/// Closes the underlying session gracefully before the adapter is disposed or replaced during failover.
///
/// The cancellation token that aborts the close request.
/// A task that represents the asynchronous operation.
Task CloseAsync(CancellationToken ct = default);
}