using Machinations.FromFlash.machinations.model;

namespace Machinations.Status
{
    class GraphStatus : IElementStatus
    {
        private readonly bool m_ended;
        private readonly string m_endCondition;
        private readonly MachinationsGraph m_graph;
        private readonly int m_step;

        public GraphStatus(MachinationsGraph graph)
        {
            m_ended = graph.Ended;
            m_endCondition = graph.EndCondition;
            m_graph = graph;
            m_step = m_graph.Step;
        }


        public int Step { get { return m_step; } }
        public void Restore()
        {
            m_graph.EndCondition = m_endCondition;
            m_graph.Ended = m_ended;
        }

        public bool NeedNewStatus()
        {
            if (m_graph.Ended != m_ended)
                return true;
            if (m_endCondition == null)
                return m_graph.EndCondition != null;
            else return !m_endCondition.Equals(m_graph.EndCondition);
        }
    }
}