using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.PlasmaStateSystem
{
    /// <summary>
    /// A small class that holds a reference to a target state and a condition.
    /// The transition should carry the current state to the target state provided a 
    /// condition passes.
    /// </summary>
    public class Transition : Transitionlike
    {
        protected Statelike targetState;
        protected TransitionCondition condition;

        /// <summary>
        /// Initializes a new instance of the <see cref="Transition"/> class.
        /// </summary>
        /// <param name="targetState">State of the target.</param>
        public Transition(Statelike targetState)
        {
            this.targetState = targetState;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Transition"/> class.
        /// </summary>
        /// <param name="targetState">State of the target.</param>
        /// <param name="condition">The condition.</param>
        public Transition(Statelike targetState, TransitionCondition condition) : this(targetState)
        {
            this.condition = condition;
        }

        /// <summary>
        /// If the <see cref="TransitionCondition" /> of this transition like
        /// object evaluates as true this returns the state object stored by
        /// the transition, otherwise it returns false.
        /// </summary>
        /// <returns></returns>
        public Statelike GetState()
        {
            return this.targetState;
        }

        /// <summary>
        /// Gets the condition of this transition like object. This condition
        /// can be used to check whether or not the transition can pass.
        /// </summary>
        /// <returns>
        /// The condidition that this transition like needs to pass.
        /// </returns>
        public TransitionCondition GetCondition()
        {
            return this.condition;
        }

        /// <summary>
        /// Does this transition like object use conditions to check if this
        /// transition can pass.
        /// </summary>
        /// <returns>
        /// Whether or not this transition like object requires
        /// a condition to pass.
        /// </returns>
        public bool IsConditional()
        {
            return this.condition != null;
        }

        /// <summary>
        /// Returns true if the condition on this transition passes.
        /// </summary>
        /// <returns></returns>
        public bool Passes()
        {
            return this.condition();
        }
    }
}
