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

namespace DXGfxLib
{
    /// <summary>
    /// Events are very brute. They are only three strings, a time value (the time at which we should fire them) and a boolean
    /// stating whether they have been fired or not. This is brute but pretty flexible as you can put pretty much everything in
    /// strings, even source code that has to be compiled... everything. Obviously this class will be derived for more specific
    /// event types but for the moment this is just the base class, the most generic possible event for this library.
    /// </summary>
    public class Event : IComparable
    {
        /// <summary>
        /// Name of the event.
        /// </summary>
        public string name;
        /// <summary>
        /// Time value after which the event should have been fired. These are time offset relatives to the start time of the
        /// simulation (when you have hit Play in the Editor or when you have started the scene by code).
        /// </summary>
        public float timeOffset;
        /// <summary>
        /// Let's say we want our events to have type. We can write a type here. This can be used by scripts processing events.
        /// </summary>
        public string type;
        /// <summary>
        /// A value is an important thing. Let's say Type can be used in scripts to know what kind of reaction there should be
        /// to the event, the value can contain parameters for that reaction/behavior.
        /// </summary>
        public string value;
        /// <summary>
        /// If this boolean is false, it means we have not fired it yet.
        /// </summary>
        public bool fired = false;

        /// <summary>
        /// Default constructor.
        /// </summary>
        public Event()
        {
        }

        /// <summary>
        /// This constructor sets all the Event member values.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="timeOffset"></param>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <param name="fired"></param>
        public Event(string name, float timeOffset, string type, string value, bool fired)
        {
            this.name = name;
            this.timeOffset = timeOffset;
            this.type = type;
            this.value = value;
            this.fired = fired;
        }

        /// <summary>
        /// When we stop the simulation we should reset all our events so when we hit Start again we can fire them again.
        /// </summary>
        public void Reset()
        {
            fired = false;
        }

        /// <summary>
        /// We will certainly want to sort our events based on their time value. THis method does just thaT.
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public int CompareTo(Event evt)
        {
            return timeOffset.CompareTo(evt.timeOffset);
        }

        /// <summary>
        /// We will certainly want to sort our events based on their time value. THis method does just thaT.
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public int CompareTo(Object obj)
        {
            Event evt = obj as Event;

            if (evt == null)
            {
                return -1;
            }
            else
            {
                return CompareTo(evt);
            }
        }
    }
}
