

using System.ComponentModel;
using System.Globalization;
using System.Xml.Serialization;
using CrossCutting;



namespace BallotTemplates
{
    
    
    
    [XmlType("BoundObject", Namespace = "urn:scan-omr:template")]
    public abstract class BoundObject : IdentifiedObject
    {
        
        private PointF _bottomRight = new PointF(0, 0);

        
        private PointF _topLeft = new PointF(0, 0);
        

        
        
        
        [XmlIgnore]
        public PointF TopLeft
        {
            get => _topLeft;
            set
            {
                _topLeft = value;
                OnPropertyChange("TopLeft");
            }
        }

        
        
        
        [XmlIgnore]
        public PointF TopRight => GetTopRight();

        
        
        
        [XmlIgnore]
        public PointF BottomRight
        {
            get => _bottomRight;
            set
            {
                _bottomRight = value;
                OnPropertyChange("BottomRight");
            }
        }

        
        
        
        [XmlIgnore]
        public PointF BottomLeft => GetBottomLeft();

        
        
        
        [XmlAttribute("topLeft")]
        [Browsable(false)]
        public string XmlTopLeft
        {
            get =>
                $"{TopLeft.X.ToString(CultureInfo.InvariantCulture)}, {TopLeft.Y.ToString(CultureInfo.InvariantCulture)}"
            ;
            set
            {
                var comps = value.Split(',');
                TopLeft = new PointF(float.Parse(comps[0], CultureInfo.InvariantCulture), float.Parse(comps[1], CultureInfo.InvariantCulture));
            }
        }

        
        
        
        [XmlAttribute("bottomRight")]
        [Browsable(false)]
        public string XmlBottomRight
        {
            get =>
                $"{BottomRight.X.ToString(CultureInfo.InvariantCulture)}, {BottomRight.Y.ToString(CultureInfo.InvariantCulture)}"
            ;
            set
            {
                var comps = value.Split(',');
                BottomRight = new PointF(float.Parse(comps[0], CultureInfo.InvariantCulture),
                    float.Parse(comps[1], CultureInfo.InvariantCulture));
            }
        }

        protected virtual PointF GetTopRight()
        {
            return new PointF(_bottomRight.X, _topLeft.Y);
        }

        protected virtual PointF GetBottomLeft()
        {
            return new PointF(_topLeft.X, _bottomRight.Y);
        }
        
        
        
        
        
        
        
        
        

        
        
        
        
        
        
    }
}
