using System;
using System.Globalization;
using System.Windows;
using System.Xml;

namespace Machinations.FromFlash.graph
{
    /// <summary>
    /// ancestor of all types of nodes
    /// </summary>
    public class GraphNode : GraphElement 
    {
        public Point m_position;
		//public NodeClass m_node;
		
		public GraphNode()
        {
            m_position = new Point();
        }


        //jen pro nacitani
        public Point Position
        {
            get { return m_position; }
            set { m_position = value;}
        }

        public virtual NodeClass NodeClass => NodeClass.None;
       
        public override XmlElement GenerateXml(XmlDocument document, XmlElement element = null)
		{
		    if (element == null)
		    {
                element = document.CreateElement("node");
            }
		    element = base.GenerateXml(document, element);
		    element.SetAttribute("symbol", NodeClass.ToString());
            element.SetAttribute("x", Math.Round(Position.X) + "");
            element.SetAttribute("y", Math.Round(Position.Y) + "");
            return element;
		}
		
		public override void ReadXml(XmlElement element) 
		{
            base.ReadXml(element);
            m_position.X = double.Parse(element.GetAttribute("x"), CultureInfo.InvariantCulture);
		    m_position.Y = double.Parse(element.GetAttribute("y"), CultureInfo.InvariantCulture);
        }

        public override void CopyShift()
        {
            m_position = new Point(m_position.X + 20, m_position.Y + 20);
        }

        public override Point GetPosition()
        {
            return m_position;
        }
    }

    public class CompatibilityNode : GraphNode
    {
        public override NodeClass NodeClass => NodeClass.None;

        public override XmlElement GenerateXml(XmlDocument document, XmlElement element = null)
        {
            throw new NotImplementedException("Nemel by se ukladat");
        }
    }
}
