package ru.dbotthepony.mc.otm.storage.powered

import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import ru.dbotthepony.mc.otm.storage.IStorageAcceptor
import ru.dbotthepony.mc.otm.storage.IStorageComponent
import ru.dbotthepony.mc.otm.storage.IStorageProvider
import ru.dbotthepony.mc.otm.storage.StorageStack
import java.util.function.Supplier

class PoweredComponent<T : StorageStack<T>>(
	val parent: IStorageComponent<T>,
	energy: Supplier<IMatteryEnergyStorage>
) : IStorageComponent<T>, IStorageProvider<T> by PoweredStorageProvider(parent, energy), IStorageAcceptor<T> by PoweredStorageAcceptor(parent, energy) {
	constructor(provider: IStorageProvider<T>, acceptor: IStorageAcceptor<T>, energy: Supplier<IMatteryEnergyStorage>) : this(IStorageComponent.C(provider, acceptor), energy)
	constructor(acceptor: IStorageAcceptor<T>, provider: IStorageProvider<T>, energy: Supplier<IMatteryEnergyStorage>) : this(IStorageComponent.C(provider, acceptor), energy)

	override val storageType: StorageStack.Type<T>
		get() = parent.storageType

	override fun equals(other: Any?): Boolean {
		return other is PoweredComponent<*> && parent == other.parent
	}

	override fun hashCode(): Int {
		return parent.hashCode()
	}

	override fun toString(): String {
		return "PoweredComponent[$parent]"
	}
}
