using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace LabelerCore.Data
{

    public class FeatureHeader : IXmlSerializable
    {
        public uint Index { get;  set; }
        public string Name { get; set; }
        public double Weight { get; set; }

        private FeatureHeader() { }

        public FeatureHeader(uint index, string name, double weight)
        {
            Index = index;
            Name = name;
            Weight = weight;
        }

        public FeatureHeader(XmlElement xml)
        {
            Index = uint.Parse(xml.GetAttribute("Index"));
            Name = xml.GetAttribute("Name");
        }


        public XElement getXElement()
        {
            return new XElement(XmlTags.FeatureXmlTag, "",
                 new XAttribute("Index", Index),
                 new XAttribute("Name", Name));
        }

        public void WriteXml(XmlWriter writer)
        {
            XElement xElem = getXElement();
            xElem.WriteTo(writer);
        }

        public void ReadXml(XmlReader reader)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(reader);
            Index = uint.Parse(doc.DocumentElement.GetAttribute("Index"));
            Name = doc.DocumentElement.GetAttribute("Name");
        }

        public XmlSchema GetSchema()
        {
            return (null);
        }

    }

}
