using System;
using XGame.Framework.Map;
using XGame.Framework.Quality;
using XGame.Framework.Time;
using XGame.Framework.UI;

namespace XGame.Framework.Nodes
{
    public class NodeTreeBuilder
    {
        public INodeTree Product { get; private set; }
        public void Build(IQualityModule qualityModule, ITimeModule timeModule, IUIModule uiModule, IMapModule mapModule, Type appNodeType)
        {
            var context = new NodeContext(qualityModule, timeModule, uiModule, mapModule);
            var root = Activator.CreateInstance(appNodeType) as INode;
            (root as Node)?.Init(context);
            var nodeTree = new NodeTree(context, root);
            (context as INodeTreeSetter).NodeTree = nodeTree;
            Product = nodeTree;
        }
    }
}

