///Licensed under Creative Commons Attribution 4.0 License, Written by Clemens Winter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exploitation
{
    class EventQueue
    {
        LinkedList<EventRequest> eventQueue;


        public EventQueue()
        {
            eventQueue = new LinkedList<EventRequest>();
        }


        public void AddEventRequest(EventRequest eventRequest)
        {
            if (eventQueue.Count == 0)
            {
                eventQueue.AddLast(eventRequest);
                return;
            }

            LinkedListNode<EventRequest> node;
            for (node = eventQueue.Last; node != null && node.Value.Time > eventRequest.Time; node = node.Previous)
            {
                ;
            }

            if (node == null) eventQueue.AddFirst(eventRequest);
            else eventQueue.AddAfter(node, eventRequest);
        }


        public EventRequest Dequeue()
        {
            EventRequest eventRequest = eventQueue.First.Value;
            eventQueue.RemoveFirst();
            return eventRequest;
        }


        public bool EventsLeft { get { return eventQueue.Count > 0; } }
        
        
    }
}
