package ru.dbotthepony.mc.otm.capability.energy

import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.core.math.Decimal

class ProxiedEnergyStorage<T : IMatteryEnergyStorage>(var parent: T? = null) : IMatteryEnergyStorage {
	override fun extractEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
		return parent?.extractEnergy(howMuch, simulate) ?: Decimal.ZERO
	}

	override fun receiveEnergy(howMuch: Decimal, simulate: Boolean): Decimal {
		return parent?.receiveEnergy(howMuch, simulate) ?: Decimal.ZERO
	}

	override var batteryLevel: Decimal
		get() = parent?.batteryLevel ?: Decimal.ZERO
		set(value) { parent?.batteryLevel = value }
	override val maxBatteryLevel: Decimal
		get() = parent?.maxBatteryLevel ?: Decimal.ZERO
	override val energyFlow: FlowDirection
		get() = parent?.energyFlow ?: FlowDirection.NONE

	override val canSetBatteryLevel: Boolean
		get() = parent?.canSetBatteryLevel ?: false
	override val missingPower: Decimal
		get() = parent?.missingPower ?: Decimal.ZERO

	override fun drainBattery(): Boolean {
		return parent?.drainBattery() ?: false
	}

	override fun fillBattery(): Boolean {
		return parent?.fillBattery() ?: false
	}
}
