using System;
using System.Collections;
using System.Windows;
using Xamarin.Forms;

namespace DataDisplay.DataSource
{
    /// <summary>This enumerator enumerates given enumerable object as sequence of points</summary>
    /// <typeparam name="T">Type parameter of source IEnumerable</typeparam>
	public sealed class EnumerablePointEnumerator<T> : IPointEnumerator {
		private readonly EnumerableDataSource<T> dataSource;
		private readonly IEnumerator enumerator;

		public EnumerablePointEnumerator(EnumerableDataSource<T> dataSource) {
			this.dataSource = dataSource;
			enumerator = dataSource.Data.GetEnumerator();
		}

		public bool MoveNext() 
    {
      try{return enumerator.MoveNext();}
      catch(InvalidOperationException){return false;}
		}

		public void GetCurrent(ref Point p) {
			dataSource.FillPoint((T)enumerator.Current, ref p);
		}

		public void ApplyMappings(BindableObject target) {
			dataSource.ApplyMappings(target, (T)enumerator.Current);
		}

		public void Dispose() {
			//enumerator.Reset();
		}
	}
}
