package ru.dbotthepony.mc.otm.matter

import com.mojang.datafixers.util.Either
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item
import ru.dbotthepony.mc.otm.core.math.Decimal

interface IRegistryEntry : IMatterValue {
	val name: Either<ResourceLocation, TagKey<Item>>
	override val matter: Decimal
	override val complexity: Double
	val priority: Int

	fun freeze(): IRegistryEntry {
		return this
	}

	companion object : IRegistryEntry {
		override fun freeze(): IRegistryEntry {
			return this
		}

		override val name: Either<ResourceLocation, TagKey<Item>> = Either.left(ResourceLocation("minecraft", "air"))
		override val matter: Decimal
			get() = Decimal.ZERO
		override val complexity: Double
			get() = 0.0
		override val priority: Int
			get() = 0
	}
}

interface IMutableRegistryEntry : IRegistryEntry {
	override var matter: Decimal
	override var complexity: Double
	override var priority: Int

	override fun freeze(): IRegistryEntry {
		throw UnsupportedOperationException()
	}
}

data class RegistryEntry(
	override val name: Either<ResourceLocation, TagKey<Item>>,
	override val matter: Decimal,
	override val complexity: Double,
	override val priority: Int,
) : IRegistryEntry

data class MutableRegistryEntry(
	override val name: Either<ResourceLocation, TagKey<Item>>,
	override var matter: Decimal,
	override var complexity: Double,
	override var priority: Int,
) : IMutableRegistryEntry {
	override fun freeze(): IRegistryEntry {
		return RegistryEntry(name, matter, complexity, priority)
	}
}
