using System.Collections.Generic;

namespace ZionRobot.Models.Source
{
    public class BlockElement
    {
        private string mainTag = @"Block";

        public string Name { get; set; }
        public List<Source.Action> Actions { get; set; }

        public BlockElement(System.Xml.XmlElement node)
        {
            Name = node.GetAttribute(@"Name");

            Actions = new List<Source.Action>();

            foreach (System.Xml.XmlElement action in node.SelectNodes(@"Action"))
            {
                Actions.Add(new Source.Action(action));
            }
        }

        public System.Xml.XmlElement AppendTo(System.Xml.XmlDocument doc)
        {
            System.Xml.XmlElement root = doc.CreateElement(mainTag);

            root.SetAttribute(@"Name", Name);

            Actions.ForEach(action =>
            {
                root.AppendChild(action.AppendTo(doc));
            });

            return root;
        }
    }
}
