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

namespace Cryville.Crtr.Event {
	public class EventBatch : IComparable<EventBatch>, IEnumerable<StampedEvent> {
		public float Time {
			get;
			private set;
		}

		readonly List<StampedEvent> queue = new List<StampedEvent>();
		public int Count {
			get { return queue.Count; }
		}

		public EventBatch(float time) {
			Time = time;
		}

		public StampedEvent this[int index] {
			get { return queue[index]; }
		}

		public void Add(StampedEvent ev) {
			Enqueue(ev);
		}

		public void Enqueue(StampedEvent ev) {
			int i = queue.BinarySearch(ev);
			if (i < 0) queue.Insert(~i, ev);
		}

		public int CompareTo(EventBatch other) {
			return this.Time.CompareTo(other.Time);
		}

		public IEnumerator<StampedEvent> GetEnumerator() {
			return queue.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}
	}
}
