package net.pokeranalytics.android.util.enumerations

import net.pokeranalytics.android.exceptions.EnumIdentifierNotFoundException
import net.pokeranalytics.android.exceptions.MisconfiguredSavableEnumException

interface IntSearchable<T : IntIdentifiable> {

	fun valuesInternal(): Array<T>

	fun valueByIdentifier(identifier: Int) : T {
		val values = this.valuesInternal().filter { it.uniqueIdentifier == identifier }
		return when (values.size) {
			0 -> throw EnumIdentifierNotFoundException("Savable enumeration uniqueIdentifier $identifier not found")
			1 -> values.first()
			else -> throw MisconfiguredSavableEnumException("Savable enumeration has multiple elements with uniqueIdentifier $identifier")
		}
	}

}

interface IntIdentifiable {
	var uniqueIdentifier: Int
}
