using System.Collections.Generic;
using System.Windows;
using System.Xml;
using Machinations.FromFlash.graph;
using Machinations.FromFlash.machinations.model;

namespace Machinations.UserComponents
{
    public class OuterInOut : InOutBase
    {
        private int m_instanceNumber;
        private int m_ucNumber;

        public OuterInOut()
        {
            
        }
        public OuterInOut(IUserComponentSchema userComponent, Point position, int instanceNumber, int cardNumber, IUserComponentSchema schema, bool input)
            :base(userComponent, position, cardNumber)
        {
            m_input = input;
            m_userComponent = schema;
            m_instanceNumber = instanceNumber;
        }

        public override NodeClass NodeClass => NodeClass.OuterInOut;

        public List<MachinationsConnection> OuterConnections
        {
            get { return m_connections; }
        }

        public int UcNumber
        {
            get { return m_ucNumber; }
        }

        public int InstanceNumber
        {
            get { return m_instanceNumber; }
        }

        public override string InOutType { get { return "OuterInOut"; } }
        protected override bool Inner { get {return false;} }

        public override XmlElement GenerateXml(XmlDocument document, XmlElement element = null)
        {
            var el = base.GenerateXml(document, element);
            el.SetAttribute("UcNumber", m_userComponent.UcId.ToString());
            el.SetAttribute("InstanceNumber", m_instanceNumber.ToString());
            el.SetAttribute("Input", m_input.ToString());
            return el;
        }

        public override void ReadXml(XmlElement element)
        {
            m_ucNumber = int.Parse(element.GetAttribute("UcNumber"));
            m_instanceNumber = int.Parse(element.GetAttribute("InstanceNumber"));
            m_input = bool.Parse(element.GetAttribute("Input"));
            base.ReadXml(element);
        }

        protected override bool DirectionChecked(bool directionIn)
        {
            return m_input != directionIn;
        }
    }
}
