using System;
using System.Xml;
using ZionSchematics.Models.SearchControlTypes;

namespace ZionSchematics.Models
{
    [Serializable]
    public class SearchControl
    {
        public ISearchControl Type;
        public int NumberOfHypotheses { get; set; }

        public SearchControl()
        {
            this.NumberOfHypotheses = 0;
            this.Type = SearchControlFactory.construct(@"OPTIONAL");
        }

        public SearchControl(string type, int numberofhypotheses)
        {
            this.Type = SearchControlFactory.construct(type);
            this.NumberOfHypotheses = numberofhypotheses;
        }

        public XmlElement Save(XmlDocument context)
        {
            XmlElement tag = context.CreateElement(@"search-control");

            XmlElement type = context.CreateElement(@"type");
            XmlElement hypoteses = context.CreateElement(@"hypotheses");

            type.InnerText = this.Type.Rule;
            hypoteses.InnerText = this.NumberOfHypotheses.ToString();

            tag.AppendChild(type);
            tag.AppendChild(hypoteses);

            return tag;
        }
    }
}
