namespace ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;

public enum TemplateTreeNodeKind
{
    Folder,
    Template,

    /// <summary>
    /// Composition slot under a parent Template — produced only by callers that
    /// supply <c>TemplateFolderTree.ExtraTemplateChildren</c>. The Transport
    /// Export wizard intentionally never emits this kind (compositions aren't
    /// independently exportable); the Templates page uses it to surface slots.
    /// </summary>
    Composition,
}

/// <summary>
/// Adapter node used by <c>TemplateFolderTree</c> to model the template-folder
/// hierarchy in a TreeView. Folder nodes carry sub-folders + their templates as
/// children; template nodes are leaves unless the caller injects extras via
/// <c>TemplateFolderTree.ExtraTemplateChildren</c> (e.g. composition slots).
/// </summary>
public sealed class TemplateTreeNode
{
    /// <summary>Discriminator indicating whether this node represents a folder, template, or composition slot.</summary>
    public required TemplateTreeNodeKind Kind { get; init; }
    /// <summary>Database id of the underlying folder, template, or composition record.</summary>
    public required int Id { get; init; }
    /// <summary>Display name of the node.</summary>
    public required string Name { get; init; }
    /// <summary>Child nodes (sub-folders, templates, or composition slots).</summary>
    public List<TemplateTreeNode> Children { get; } = new();

    /// <summary>Stable key for TreeView selection / expansion tracking.</summary>
    public string Key => Kind switch
    {
        TemplateTreeNodeKind.Folder => $"f:{Id}",
        TemplateTreeNodeKind.Template => $"t:{Id}",
        TemplateTreeNodeKind.Composition => $"c:{Id}",
        _ => $"x:{Id}",
    };
}
