using UnityEngine;
using System.Collections;

public class Tile {
	public enum Type {
		NORMAL,
		BLOCKED,
		RED,
		GREEN,
		BLUE
	}

	private GameObject tileObject;
	private Type type;
	private GridPos position;

	private Unit unit;

	public Tile(Type t, GridPos pos) {
		type = t;
		position = pos;

		switch (type) {
			case Type.NORMAL:
				tileObject = (GameObject)MonoBehaviour.Instantiate(GameAssets.get().getTileNormal());
				break;
			case Type.BLOCKED:
				tileObject = (GameObject)MonoBehaviour.Instantiate(GameAssets.get().getTileBlocked());
				break;
			case Type.RED:
				tileObject = (GameObject)MonoBehaviour.Instantiate(GameAssets.get().getTileRed());
				break;
			case Type.GREEN:
				tileObject = (GameObject)MonoBehaviour.Instantiate(GameAssets.get().getTileGreen());
				break;
			case Type.BLUE:
				tileObject = (GameObject)MonoBehaviour.Instantiate(GameAssets.get().getTileBlue());
				break;
		}

		tileObject.transform.position = position.getWorldPosition();
		setBlockedRenderMode(true);
	}
	
	public void setBlockedRenderMode(bool blocked) {
		tileObject.transform.Find("Pass").gameObject.SetActive(!blocked);
		tileObject.transform.Find("Block").gameObject.SetActive(blocked);
	}

	public Type getType() {
		return type;
	}
	
	public GridPos getPosition() {
		return position;
	}

	public Unit getUnit() {
		return unit;
	}

	public void setUnit(Unit u) {
		unit = u;
	}
	
	public bool hasUnit() {
		return unit != null;
	}
}
