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

import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import ru.dbotthepony.mc.otm.storage.IStorage
import ru.dbotthepony.mc.otm.storage.IStorageComponent
import ru.dbotthepony.mc.otm.storage.IStorageProvider
import ru.dbotthepony.mc.otm.storage.IVirtualStorageComponent
import ru.dbotthepony.mc.otm.storage.StorageStack
import ru.dbotthepony.mc.otm.storage.VirtualComponent
import java.util.*
import java.util.function.Supplier

class PoweredVirtualComponent<T : StorageStack<T>>(
	val parent: IVirtualStorageComponent<T>,
	energy: Supplier<IMatteryEnergyStorage>
) : IVirtualStorageComponent<T>, IStorageComponent<T> by PoweredComponent(parent, energy) {
	constructor(type: StorageStack.Type<T>, energy: Supplier<IMatteryEnergyStorage>) : this(VirtualComponent(type), energy)

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

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

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

	override fun onStackAdded(stack: T, id: UUID, provider: IStorageProvider<T>) = parent.onStackAdded(stack, id, provider)
	override fun onStackChanged(stack: T, id: UUID) = parent.onStackChanged(stack, id)
	override fun onStackRemoved(id: UUID) = parent.onStackRemoved(id)
	override fun add(identity: IStorage<T>) = parent.add(identity)
	override fun remove(identity: IStorage<T>) = parent.remove(identity)
	override fun contains(identity: IStorage<T>) = parent.contains(identity)
}
