package common.init;

import java.util.List;
import java.util.Map;

import common.block.Block;
import common.block.BlockDynamicLiquid;
import common.block.BlockLiquid;
import common.block.BlockStaticLiquid;
import common.collect.Lists;
import common.collect.Maps;
import common.material.Material;

public abstract class FluidRegistry {
	public static enum LiquidType {
		COLD(Material.coldFluid), HOT(Material.hotFluid), WATER(Material.water), LAVA(Material.lava);
		
		public final Material material;
		
		private LiquidType(Material material) {
			this.material = material;
		}
	}
	
	static class FluidInfo {
		private final int id;
		private final BlockStaticLiquid stBlock;
		private final BlockDynamicLiquid dyBlock;
		private final Object stAnim;
		private final Object dyAnim;
		
		private FluidInfo(int id, BlockStaticLiquid stBlock, BlockDynamicLiquid dyBlock, Object stAnim, Object dyAnim) {
			this.id = id;
			this.stBlock = stBlock;
			this.dyBlock = dyBlock;
			this.stAnim = stAnim;
			this.dyAnim = dyAnim;
		}
	}
	
	private static int currentId;
	
	private static final List<FluidInfo> FLUIDS = Lists.newArrayList();
	private static final Map<Block, Integer> ID_MAP = Maps.newHashMap();
	
	public static int getFluidMeta(BlockLiquid block) {
		return ID_MAP.get(block).intValue();
	}
	
	public static BlockDynamicLiquid getFluidBlock(int meta) {
		return meta < 0 || meta >= currentId ? Blocks.flowing_water : FLUIDS.get(meta).dyBlock;
	}
	
	public static BlockStaticLiquid getStaticBlock(int meta) {
		return meta < 0 || meta >= currentId ? Blocks.water : FLUIDS.get(meta).stBlock;
	}
	
	public static Object getFluidAnim(int meta) {
		return FLUIDS.get(meta).dyAnim;
	}
	
	public static Object getStaticAnim(int meta) {
		return FLUIDS.get(meta).stAnim;
	}
	
	public static int getNumFluids() {
		return currentId;
	}
	
	public static BlockStaticLiquid getStaticBlock(BlockDynamicLiquid dy) {
		return FLUIDS.get(ID_MAP.get(dy).intValue()).stBlock;
	}
	
	public static BlockDynamicLiquid getDynamicBlock(BlockStaticLiquid st) {
		return FLUIDS.get(ID_MAP.get(st).intValue()).dyBlock;
	}
	
	static void registerFluid(BlockStaticLiquid stBlock, BlockDynamicLiquid dyBlock, Object stAnim, Object dyAnim) {
		FluidInfo info = new FluidInfo(currentId++, stBlock, dyBlock, stAnim, dyAnim);
		FLUIDS.add(info);
		ID_MAP.put(stBlock, info.id);
		ID_MAP.put(dyBlock, info.id);
	}
}
