namespace ZB.MOM.WW.OtOpcUa.Core.Authorization;

/// <summary>
///     Address of a node in the 6-level scope hierarchy the Phase 6.2 evaluator walks.
///     Assembled by the dispatch layer from the node's namespace + UNS path + tag; passed
///     to <see cref="IPermissionEvaluator"/> which walks the matching trie path.
/// </summary>
/// <remarks>
///     <para>Per the Phase 6.2 Stream B plan the hierarchy is
///     <c>Cluster → Namespace → UnsArea → UnsLine → Equipment → Tag</c> for all
///     (Equipment-kind) namespaces. Galaxy is a standard Equipment-kind driver, so Galaxy
///     points are ordinary equipment tags that resolve through this same walk.</para>
///
///     <para>Unset mid-path levels (e.g. a Cluster-scoped request with no UnsArea) leave
///     the corresponding id <c>null</c>. The evaluator walks as far as the scope goes +
///     stops at the first null.</para>
/// </remarks>
public sealed record NodeScope
{
    /// <summary>Cluster the node belongs to. Required.</summary>
    public required string ClusterId { get; init; }

    /// <summary>Namespace within the cluster. Null is not allowed for a request against a real node.</summary>
    public string? NamespaceId { get; init; }

    /// <summary>UNS area (e.g. "warsaw-west") below the namespace.</summary>
    public string? UnsAreaId { get; init; }

    /// <summary>UNS line below the area.</summary>
    public string? UnsLineId { get; init; }

    /// <summary>Equipment row below the line.</summary>
    public string? EquipmentId { get; init; }

    /// <summary>Target tag id when the scope addresses a specific tag; null for equipment-level scopes.</summary>
    public string? TagId { get; init; }

    /// <summary>Which hierarchy applies. Currently only Equipment-kind (UNS) exists.</summary>
    public required NodeHierarchyKind Kind { get; init; }
}

/// <summary>Selector for the scope-hierarchy shape.</summary>
public enum NodeHierarchyKind
{
    /// <summary><c>Cluster → Namespace → UnsArea → UnsLine → Equipment → Tag</c> — UNS / Equipment kind.</summary>
    Equipment,
}
