using System;
using System.Collections.Generic;

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

        public TreeModel()
        {
        }

        public TreeModel(T node, IReadOnlyCollection<TreeModel<T>> childs)
        {
            Node = node;
            Childs = childs;
        }

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