package ru.dbotthepony.mc.otm.menu.tech

import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.level.block.Blocks
import ru.dbotthepony.mc.otm.block.entity.tech.FlywheelBatteryBlockEntity
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
import ru.dbotthepony.mc.otm.network.StreamCodecs
import ru.dbotthepony.mc.otm.network.nullable
import ru.dbotthepony.mc.otm.registry.game.MMenus
import java.util.function.BooleanSupplier
import java.util.function.Supplier

class FlywheelBatteryMenu(
	containerId: Int,
	inventory: Inventory,
	tile: FlywheelBatteryBlockEntity? = null
) : MatteryMenu(MMenus.FLYWHEEL_BATTERY, containerId, inventory, tile) {
	val formed = mSynchronizer.computedBoolean(BooleanSupplier { tile?.formed ?: false })
	val energy = ProfiledLevelGaugeWidget(this, tile?.energyInterfaceTarget)
	val core = mSynchronizer.computed(Supplier { tile?.currentlyUsedCore }, CORE_TYPE_CODEC)
	val currentLossPerTick = mSynchronizer.computedDecimal(Supplier { tile?.currentLossPerTick ?: Decimal.ZERO })

	companion object {
		private val CORE_TYPE_CODEC = MatteryStreamCodec.MapEntry(StreamCodecs.BLOCK_TYPE, StreamCodecs.VAR_INT).nullable()
	}
}
