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

namespace ZionVault.Synonym
{
    public class Word
    {
        private List<string> synonyms;

        public List<string> Synonyms { get => synonyms; set => this.synonyms = value; }

        
        public Word(XmlNode node)
        {
            synonyms = new List<string>();
            foreach (XmlElement synonym in node.SelectNodes(@"synonym")) {
                synonyms.Add(synonym.GetAttribute(@"description"));
            };
        }

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

            if (synonyms.Count > 0)
            {
                synonyms.ForEach(synonym =>
                {
                    XmlElement element = document.CreateElement(@"synonym");
                    element.SetAttribute(@"description", synonym);
                    root.AppendChild(element);
                });
            }
            return root;
        }
    }
}
