using System;
using Machinations.FromFlash.graph;
using Machinations.FromFlash.machinations.model;

namespace Machinations.Log
{
    /// <summary>
    /// record for one action
    /// </summary>
    public class ActionLog : IComparable<ActionLog>
    {
        private readonly int m_step;
        private readonly GraphElement m_element;
        private readonly ActivationMode m_cause;

        public ActionLog(int step, GraphElement element, ActivationMode cause)
        {
            m_step = step;
            m_element = element;
            m_cause = cause;
        }

        public int Step
        {
            get { return m_step; }
        }

        public ActivationMode Mode
        {
            get { return m_cause; }
        }
        
        public string Cause
        {
            get { return m_cause.ToString(); }
        }

        public string ElementName
        {
            get { return m_element.GetMMName(); }
        }

        public NodeClass ElementClass
        {
            get {
                if (m_element is MachinationsNode)
                {
                    return ((MachinationsNode) m_element).NodeClass;
                }
                return NodeClass.None;
            }
        }

        public void Select(bool select)
        {
            if(select)
                m_element.Selected();
            else
                m_element.UnSelected();
        }

        public int CompareTo(ActionLog other)
        {
            if (Step > other.Step) return -1;
            if (Step == other.Step) return 0;
            return 1;
        }
    }
}
