package ru.dbotthepony.kstarbound.defs.world

import com.google.common.collect.ImmutableList
import ru.dbotthepony.kstarbound.Registry
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.defs.tile.TileModifierDefinition
import ru.dbotthepony.kstarbound.json.NativeLegacy
import ru.dbotthepony.kstarbound.json.builder.JsonFactory

@JsonFactory
data class Biome(
	val hueShift: Double = 0.0,
	val materialHueShift: Int = 0,
	val baseName: String,
	val description: String,
	val mainBlock: NativeLegacy.Tile,
	val subBlocks: ImmutableList<NativeLegacy.Tile> = ImmutableList.of(),
	val ores: ImmutableList<Pair<NativeLegacy.TileMod, Double>> = ImmutableList.of(),
	val musicTrack: AmbientNoisesDefinition? = null,
	val ambientNoises: AmbientNoisesDefinition? = null,
	val surfacePlaceables: BiomePlaceables = BiomePlaceables(),
	val undergroundPlaceables: BiomePlaceables = BiomePlaceables(),
	val parallax: Parallax? = null,
) {
	@JvmName("hueShiftTile")
	fun hueShift(block: Registry.Entry<TileDefinition>): Float {
		if (block == mainBlock.native.entry) {
			return hueShift.toFloat()
		}

		return 0f
	}

	@JvmName("hueShiftTile")
	fun hueShift(block: Registry.Ref<TileDefinition>): Float {
		if (block == mainBlock.native) {
			return hueShift.toFloat()
		}

		return 0f
	}

	@JvmName("hueShiftMod")
	fun hueShift(mod: Registry.Entry<TileModifierDefinition>): Float {
		if (
			mod == surfacePlaceables.grassMod.native.entry ||
			mod == undergroundPlaceables.grassMod.native.entry ||
			mod == surfacePlaceables.ceilingGrassMod.native.entry ||
			mod == undergroundPlaceables.ceilingGrassMod.native.entry
		) {
			return hueShift.toFloat()
		}

		return 0f
	}

	@JvmName("hueShiftMod")
	fun hueShift(mod: Registry.Ref<TileModifierDefinition>): Float {
		if (
			mod == surfacePlaceables.grassMod.native ||
			mod == undergroundPlaceables.grassMod.native ||
			mod == surfacePlaceables.ceilingGrassMod.native ||
			mod == undergroundPlaceables.ceilingGrassMod.native
		) {
			return hueShift.toFloat()
		}

		return 0f
	}
}
