package ru.dbotthepony.kstarbound.defs.world

import com.google.gson.reflect.TypeToken
import ru.dbotthepony.kstarbound.json.builder.DispatchingAdapter
import ru.dbotthepony.kstarbound.json.builder.IStringSerializable

enum class BiomePlacementItemType(
	override val jsonName: String,
	val def: TypeToken<out BiomePlaceablesDefinition.DistributionItemData>,
	val data: TypeToken<out BiomePlaceables.Item>,
) : IStringSerializable {
	MICRO_DUNGEON("microdungeon",
	              TypeToken.get(BiomePlaceablesDefinition.MicroDungeon::class.java),
	              TypeToken.get(BiomePlaceables.MicroDungeon::class.java)
	),
	TREASURE_BOX_SET("treasurebox",
	                 TypeToken.get(BiomePlaceablesDefinition.TreasureBox::class.java),
	                 TypeToken.get(BiomePlaceables.TreasureBox::class.java)
	),
	GRASS("grass",
	      TypeToken.get(BiomePlaceablesDefinition.Grass::class.java),
	      TypeToken.get(BiomePlaceables.Grass::class.java)
	),
	BUSH("bush",
	     TypeToken.get(BiomePlaceablesDefinition.Bush::class.java),
	     TypeToken.get(BiomePlaceables.Bush::class.java)
	),
	TREE("tree",
	     TypeToken.get(BiomePlaceablesDefinition.Tree::class.java),
	     TypeToken.get(BiomePlaceables.Tree::class.java)
	),
	OBJECT("object",
	       TypeToken.get(BiomePlaceablesDefinition.Object::class.java),
	       TypeToken.get(BiomePlaceables.Object::class.java)
	),
	;

	override fun match(name: String): Boolean {
		return name.lowercase() == jsonName
	}

	companion object {
		val DEFINITION_ADAPTER = DispatchingAdapter("type", { type }, { def }, entries)
		val DATA_ADAPTER = DispatchingAdapter("type", { type }, { data }, entries)
	}
}