using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Gamelogic.Grids.Examples
{
	public class TransformedMap<TPoint> : IMap3D<TPoint>, IMeshMap<TPoint> where TPoint : IGridPoint<TPoint>
	{
		private Func<Vector3, Vector3> transformation;
		
		private IMeshMap<TPoint> meshMap;

		public TransformedMap(IMeshMap<TPoint> meshMap, Func<Vector3, Vector3> transformation)
		{
			this.transformation = transformation;
			this.meshMap = meshMap;
		}

		Vector3 IMap3D<TPoint>.this[TPoint point]
		{
			get { return transformation(meshMap.Map2D[point]); }
		}

		TPoint IMap3D<TPoint>.this[Vector3 point]
		{
			get { throw new NotImplementedException(); }
		}

		public IMap<TPoint> To2D()
		{
			return meshMap.Map2D;
		}

		public IMap<TPoint> Map2D
		{
			get { return meshMap.Map2D; }
		}

		public IEnumerable<Vector3> GetVertices(TPoint point)
		{
			return meshMap.GetVertices(point).Select(transformation);
		}

		public IEnumerable<Vector2> GetUVs(TPoint point)
		{
			return meshMap.GetUVs(point);
		}

		public IEnumerable<int> GetTriangles(TPoint point, int vertexIndex)
		{
			return meshMap.GetTriangles(point, vertexIndex);
		}
	}
}