package space.nstart.pcp.pcp_types_lib.utils

import io.github.classgraph.ClassGraph
import space.nstart.pcp.pcp_types_lib.message.KafkaEvent
import kotlin.reflect.KClass

class KafkaEventClassDiscoverer {
    companion object {
        const val KAFKA_EVENTS_PACKAGE = "space.nstart.pcp.pcp_types_lib.message"

        fun discoverKafkaEventEnums(): List<KClass<out KafkaEvent>> {
            ClassGraph()
                .enableClassInfo()
                .enableInterClassDependencies()
                .acceptPackages(KAFKA_EVENTS_PACKAGE)
                .scan()
                .use { scanResult ->
                    return scanResult
                        .getClassesImplementing(KafkaEvent::class.qualifiedName)
                        .filter { it.isEnum }
                        .map { it.loadClass().kotlin }
                        .filterIsInstance<KClass<out KafkaEvent>>()
                }
        }
    }
}