using Opc.Ua;
using Opc.Ua.Server;
using ZB.MOM.WW.OtOpcUa.OpcUaServer.Security;
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
/// Borrowed SDK browse state; implementations must not retain or mutate the continuation object.
public sealed record ProjectedBrowseContext(NodeId Parent, RoleCarryingUserIdentity? Caller,
ContinuationPoint Continuation, long RequestStartedTimestamp);
/// A copied, caller-bound request for one projected page.
public sealed record ProjectedBrowsePageRequest(NodeId Parent, RoleCarryingUserIdentity Caller, string? Cursor,
uint MaximumResults, long RequestStartedTimestamp);
/// An immutable page snapshot; authority must remain live through emission.
public sealed record ProjectedBrowsePage(ProjectedBrowseReadiness Status, IReadOnlyList Children,
string? NextCursor, bool Complete, Func IsCurrent, long RetainedBytes = 0);
/// Per-caller synchronous lookup and bounded scheduling, never network I/O.
public interface IProjectedBrowseAccess
{
ProjectedBrowseReadiness GetOrSchedule(ProjectedBrowseContext context);
ProjectedBrowsePage GetOrSchedulePage(ProjectedBrowsePageRequest request) =>
new(ProjectedBrowseReadiness.Unavailable, [], null, false, static () => false);
/// Waits for a bounded coalesced page preparation without occupying an SDK lock.
Task WaitForPageAsync(ProjectedBrowsePageRequest request, CancellationToken cancellationToken) =>
Task.FromResult(GetOrSchedulePage(request));
}