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

namespace ZionVault.Synonym
{
    public class Search
    {
        private List<Word> words;

        public List<Word> Words { get => words; set => this.words = value; }

        public Search(XmlElement node)
        {
            words = new List<Word>();
            foreach (XmlNode word in node.SelectNodes(@"search/word"))
            {
                words.Add(new Word(word));
            }
                /*Synonyms = new List<List<string>>();
                foreach(XmlElement synonyms in node.SelectNodes(@"word"))
                {
                    List<string> w = new List<string>();
                    foreach (XmlElement synonym in synonyms.GetElementsByTagName(@"synonym")){
                        w.Add(synonym.GetAttribute(@"description"));
                    }
                    Synonyms.Add(w);
                }*/
            }

        public XmlNode Export(XmlDocument document)
        {
            XmlElement root = document.CreateElement(@"search");

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

            return root;
        }
    }
}
