using System;
using System.Collections.Generic;

namespace VCommon.DataModel
{
    public class TreeModel<T>
    {
        public T Node { get; set; }
        public IReadOnlyCollection<TreeModel<T>> Children { get; set; }

        public TreeModel()
        {
        }

        public TreeModel(T node, IReadOnlyCollection<TreeModel<T>> children)
        {
            Node = node;
            Children = children;
        }

        public void Traverse(Action<T> visitor)
        {
            visitor(Node);
            foreach (var child in Children) child.Traverse(visitor);
        }
    }
}
