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 fun extractEnergyChecked(howMuch: Decimal, simulate: Boolean): Decimal {
		return parent?.extractEnergyChecked(howMuch, simulate) ?: Decimal.ZERO
	}

	override fun receiveEnergyChecked(howMuch: Decimal, simulate: Boolean): Decimal {
		return parent?.receiveEnergyChecked(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
	}

	override fun receiveEnergy(maxReceive: Int, simulate: Boolean): Int {
		return parent?.receiveEnergy(maxReceive, simulate) ?: 0
	}

	override fun extractEnergy(maxReceive: Int, simulate: Boolean): Int {
		return parent?.extractEnergy(maxReceive, simulate) ?: 0
	}

	override fun getEnergyStored(): Int {
		return parent?.getEnergyStored() ?: 0
	}

	override fun getMaxEnergyStored(): Int {
		return parent?.getMaxEnergyStored() ?: 0
	}

	override fun canExtract(): Boolean {
		return parent?.canExtract() == true
	}

	override fun canReceive(): Boolean {
		return parent?.canReceive() == true
	}
}
