package ru.dbotthepony.mc.otm.config

import ru.dbotthepony.mc.otm.block.entity.matter.MatterReconstructorBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterDecomposerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterRecyclerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterReplicatorBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterScannerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity
import ru.dbotthepony.mc.otm.block.entity.tech.ChemicalGeneratorBlockEntity
import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.defineDecimal
import ru.dbotthepony.mc.otm.registry.MNames

object MachinesConfig : AbstractConfig("machines") {
	init {
		AndroidStationBlockEntity.registerConfig(builder)
		ChemicalGeneratorBlockEntity.registerConfig(builder)
		MatterRecyclerBlockEntity.registerConfig(builder)
		MatterBottlerBlockEntity.registerConfig(builder)
		MatterReplicatorBlockEntity.registerConfig(builder)
		MatterScannerBlockEntity.registerConfig(builder)
		MatterDecomposerBlockEntity.registerConfig(builder)
		MatterReconstructorBlockEntity.registerConfig(builder)
	}

	val PLATE_PRESS = workerValues(
		MNames.PLATE_PRESS,
		storage = Decimal(40_000),
		throughput = Decimal(200),
		powerConsumption = Decimal(15)
	)

	val STORAGE_POWER_SUPPLIER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.STORAGE_POWER_SUPPLIER, capacity = Decimal(100_000), throughput = Decimal(320))
	val STORAGE_INTERFACES = BlockEnergyStorageImpl.makeConfigEntry(builder, "STORAGE_INTERFACES", capacity = Decimal(10_000))
	val ITEM_MONITOR = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.ITEM_MONITOR)
	val DRIVE_VIEWER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.DRIVE_VIEWER)
	val DRIVE_RACK = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.DRIVE_RACK, capacity = Decimal(80_000))

	object AndroidCharger {
		val RADIUS_WIDTH: Double by builder
			.comment("Effective charger range on horizontal plane")
			.defineInRange("RADIUS_WIDTH", 16.0, 1.0, Double.MAX_VALUE)

		val RADIUS_HEIGHT: Double by builder
			.comment("Effective charger range on vertical plane")
			.defineInRange("RADIUS_HEIGHT", 4.0, 1.0, Double.MAX_VALUE)
	}

	val ANDROID_CHARGER = BlockEnergyStorageImpl.makeConfigEntry(builder, MNames.ANDROID_CHARGER, capacity = Decimal(1_000_000), throughput = Decimal(8192)) { AndroidCharger }

	val POWERED_FURNACE = workerValues(
		"POWERED_FURNACE",
		storage = Decimal(40_000),
		throughput = Decimal(200),
		powerConsumption = Decimal(20),
		workTimeMultiplier = 0.75
	)

	val POWERED_BLAST_FURNACE = workerValues(
		"POWERED_BLAST_FURNACE",
		storage = Decimal(40_000),
		throughput = Decimal(200),
		powerConsumption = Decimal(20),
		workTimeMultiplier = 0.75
	)

	val POWERED_SMOKER = workerValues(
		"POWERED_SMOKER",
		storage = Decimal(40_000),
		throughput = Decimal(200),
		powerConsumption = Decimal(10),
		workTimeMultiplier = 0.75
	)

	object Upgrades {
		init {
			builder.push("UPGRADES")
		}

		val MIN_SPEED: Double by builder
			.comment("Minimal combined upgrade speed percentage (upgrades can't decrease machine speed below this)")
			.defineInRange("MIN_SPEED", -0.8, -1.0, Double.MAX_VALUE)

		val MAX_SPEED: Double by builder
			.comment("Maximal combined upgrade speed percentage")
			.defineInRange("MAX_SPEED", Double.MAX_VALUE, 0.0, Double.MAX_VALUE)

		val MIN_ENERGY by builder
			.comment("Minimal combined energy consumption percentage (upgrades can't decrease machine energy consumption below this)")
			.defineDecimal("MIN_ENERGY", Decimal(-0.8), Decimal(-1.0))

		val MAX_ENERGY by builder
			.comment("Maximal combined energy consumption percentage")
			.defineDecimal("MAX_ENERGY", Decimal.LONG_MAX_VALUE, Decimal.ZERO)

		init {
			builder.pop()
		}
	}

	init {
		Upgrades
	}
}
