using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ZionVault.Synonym
{
    public class Area : Search
    {
        private string description;
        private List<Word> titles;

        public string Description { get => description; set => description = value; }
        public List<Word> Titles { get => titles; set => titles = value; }

        public Area(XmlElement node) : base(node)
        {
            this.description = node.GetAttribute(@"description");

            titles = new List<Word>();
            foreach(XmlElement word in node.SelectNodes(@"word")){
                titles.Add(new Word(word));
            }

            //this.search = node.SelectSingleNode(@"search") != null ? new Search(node.SelectSingleNode(@"search")) : null;
        }

        public XmlNode Export(XmlDocument document)
        {
            XmlElement root = document.CreateElement(@"area");
            root.SetAttribute(@"description", this.description);

            if (titles.Count > 0)
            {
                titles.ForEach(word =>
                {
                    root.AppendChild(word.Export(document));
                });
            }

            if(base.Words != null)
            {
                root.AppendChild(base.Export(document));
            }

            return root;
        }
    }
}
