using System;
using ZionVault.Basic;

namespace ZionVault.Binder.OCR
{
    public class Barcode : IDisposable
    {
        string value;
        string type;
        float confidence;
        Location position;

        public void Dispose()
        {
            if (position != null)
                position.Dispose();

            GC.SuppressFinalize(this);
        }

        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        public float Confidence
        {
            get { return confidence; }
            set { confidence = value; }
        }

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

        public System.Xml.XmlNode Export(System.Xml.XmlDocument context)
        {
            System.Xml.XmlElement root = context.CreateElement(@"barcode");
            root.SetAttribute(@"type", this.type.ToString());
            root.SetAttribute(@"confidence", this.confidence.ToString());
            root.SetAttribute(@"location", this.position.ToString());
            root.InnerText = this.value;
            return root;
        }

        public Barcode() { }

        public Barcode(System.Xml.XmlElement element)
        {
            this.type = element.GetAttribute(@"type");
            //this.confidence = int.Parse(element.GetAttribute(@"confidence"));
            this.confidence = float.Parse(element.GetAttribute(@"confidence"));
            this.position = new Location(element.GetAttribute(@"location"));
            this.value = element.InnerText;
        }
    }
}
