package ru.dbotthepony.mc.otm.android

import net.minecraft.network.chat.Component
import net.minecraft.network.chat.ComponentContents
import net.minecraft.network.chat.MutableComponent
import net.minecraft.network.chat.contents.TranslatableContents
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.core.getKeyNullable
import ru.dbotthepony.mc.otm.registry.MRegistry

open class AndroidFeatureType<T : AndroidFeature> {
	protected val factory: (AndroidFeatureType<T>, MatteryPlayerCapability) -> T

	constructor(factory: (MatteryPlayerCapability) -> T) : super() {
		this.factory = { _, capability -> factory.invoke(capability) }
	}

	constructor(factory: (AndroidFeatureType<T>, MatteryPlayerCapability) -> T) : super() {
		this.factory = factory
	}

	fun create(android: MatteryPlayerCapability): T {
		return factory.invoke(this, android)
	}

	open fun isApplicable(android: MatteryPlayerCapability) = true

	val registryName by lazy {
		MRegistry.ANDROID_FEATURES.getKeyNullable(this)
	}

	open val displayContents: ComponentContents by lazy {
		TranslatableContents(displayId, null, arrayOf())
	}

	open val displayName: Component by lazy {
		MutableComponent.create(displayContents)
	}

	open val displayId: String by lazy {
		registryName?.let { "android_feature.${it.namespace}.${it.path}" } ?: "android_feature.null.null"
	}
}
