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.
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.
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.
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.
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.
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.
Task> HistoryReadRawAsync(NodeId nodeId, DateTime startTime, DateTime endTime,
int maxValues, CancellationToken ct = default);
///
/// 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.
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.
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.
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.
Task CloseAsync(CancellationToken ct = default);
}