package ru.dbotthepony.mc.otm.storage.optics

import ru.dbotthepony.mc.otm.storage.IStorageEventConsumer
import ru.dbotthepony.mc.otm.storage.IStorageProvider
import ru.dbotthepony.mc.otm.storage.StorageStack
import java.util.function.IntSupplier

class ExtractPriority<S : StorageStack<S>>(private val parent: IStorageProvider<S>, private val priority: IntSupplier) : IStorageProvider<S> by parent {
	override val extractPriority: Int
		get() = priority.asInt

	override fun addListener(listener: IStorageEventConsumer<S>): Boolean {
		return parent.addListener(ListenerProxy(listener, this))
	}

	override fun removeListener(listener: IStorageEventConsumer<S>): Boolean {
		return parent.removeListener(ListenerProxy(listener, this))
	}

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

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

	override fun toString(): String {
		return "ExtractPriority[$parent with $priority]"
	}
}
