using System.Collections.Generic;
using System.Xml;

namespace ZionVault.Encoders.Xml
{
    public class ElementsGroup
    {
        private string name;
        private List<Element> elements;

        public string Name { get => name; set => name = value; }
        public List<Element> Elements { get => elements; set => elements = value; }

        public ElementsGroup()
        {
            this.elements = new List<Element>();
        }

        public ElementsGroup(string name)
        {
            this.name = name;
            this.elements = new List<Element>();
        }

        public ElementsGroup(ElementsGroup group)
        {
            this.name = group.Name;
            this.elements = group.Elements;
        }

        public void AppendTo(XmlDocument doc, XmlNode parent)
        {
            XmlElement group = doc.CreateElement(name);

            elements.ForEach(element =>
            {
                new Element(element.Name, element.Value).AppendTo(doc, group);
            });

            parent.AppendChild(group);
        }
    }
}
