using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Protocol;
namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
///
/// Sent from CentralUI to a specific site to enumerate the immediate children
/// of an OPC UA node on the live server backing the given data connection.
///
///
/// Keyed by (not id) because the site-side
/// DataConnectionManagerActor indexes its children by connection name —
/// the central UI already has the connection name in scope (dropdown), so a
/// string carries no extra plumbing across the trust boundary. The central
/// DataConnections table's id is intentionally not exposed at the site.
///
/// Name of the site-local data connection to browse against.
/// Node to browse, or null to browse from the server root (ObjectsFolder).
///
/// Opaque adapter cursor for fetching the NEXT page of children under
/// . Null on the first request; on a subsequent
/// request carry back the token from the prior .
/// Additive (appended last) so positional construction stays source-compatible.
///
///
/// Target site identifier — REQUIRED when the command is invoked via the management
/// HTTP API/CLI (the actor must route it to a site); ignored on the site side, where
/// routing already happened. Additive per the message-contract evolution rules.
///
public record BrowseNodeCommand(
string ConnectionName,
string? ParentNodeId,
string? ContinuationToken = null,
string? SiteIdentifier = null);
/// Immediate children resolved for the browsed node (this page only).
/// True when the result was clipped (frame-budget cap or adapter-reported truncation).
/// Structured failure, or null on success.
///
/// Opaque adapter cursor for the NEXT page when more children remain, or null
/// when this is the final page. Surface it back in a follow-up
/// . Additive (appended last).
///
public record BrowseNodeResult(
IReadOnlyList Children,
bool Truncated,
BrowseFailure? Failure,
string? ContinuationToken = null);
///
/// Sent from CentralUI to a specific site to run a bounded recursive search of
/// the address space on the live server backing the given data connection.
///
///
/// The address-space analogue of : where browse
/// walks one level at a time on user demand, search walks the tree itself
/// (bounded by depth + result caps) and returns the nodes whose DisplayName or
/// root-relative path contains . Keyed by
/// for the same reason as browse — the site-side
/// DataConnectionManagerActor indexes its children by connection name and
/// the central DataConnections id is intentionally not exposed at the
/// site. Routed over the same cross-cluster path as browse and resolved by the
/// owning connection's IAddressSpaceSearchable adapter.
///
/// Name of the site-local data connection to search against.
/// Case-insensitive substring matched against each node's DisplayName and root-relative path.
/// Maximum number of levels below the root to descend. Must be non-negative.
/// Maximum number of matches to return; when reached the walk stops early and is set.
///
/// Target site identifier — REQUIRED when the command is invoked via the management
/// HTTP API/CLI (the actor must route it to a site); ignored on the site side, where
/// routing already happened. Additive per the message-contract evolution rules.
///
public record SearchAddressSpaceCommand(
string ConnectionName,
string Query,
int MaxDepth,
int MaxResults,
string? SiteIdentifier = null);
/// The matched address-space nodes, in breadth-first discovery order (capped at ).
/// True when a bound (result cap or the adapter's node-visit ceiling) cut the walk short, so more matches may exist than were returned.
/// Structured failure, or null on success. Reuses the browse kinds (the search path mirrors browse exactly).
public record SearchAddressSpaceResult(
IReadOnlyList Matches,
bool CapReached,
BrowseFailure? Failure);
public record BrowseFailure(
BrowseFailureKind Kind,
string Message);
public enum BrowseFailureKind
{
ConnectionNotFound,
ConnectionNotConnected,
NotBrowsable,
Timeout,
ServerError
}