using System;
using ZionVault.Basic;

namespace ZionVault.Binder.OCR
{
    public class Word : IDisposable
    {
        private int index;
        private int quality;
        private Location position;
        private string text;

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        public int Index
        {
            get { return index; }
            set { index = value; }
        }

        public int Quality
        {
            get { return quality; }
            set { quality = value; }
        }

        public Location Location
        {
            get { return position; }
            set { position = value; }
        }

        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        public Word(int _Index, int _Quality, Location _Position, string _Text)
        {
            this.index = _Index;
            this.quality = _Quality;
            this.position = _Position;
            this.text = _Text;
        }

        public Word(System.Xml.XmlElement node)
        {
            this.index = int.Parse(node.GetAttribute(@"index"));
            this.quality = int.Parse(node.GetAttribute(@"quality"));
            this.position = new Location(node.GetAttribute(@"location"));
            this.text = node.InnerText;
        }

        public System.Xml.XmlNode Export(System.Xml.XmlDocument context)
        {
            System.Xml.XmlElement root = context.CreateElement(@"word");
            root.SetAttribute(@"index", this.index.ToString());
            root.SetAttribute(@"quality", this.quality.ToString());
            root.SetAttribute(@"location", this.position.ToString());
            root.InnerText = this.text;
            return root;
        }
    }
}
