package de.accso.flexinale.common.shared_kernel;

import java.util.Arrays;

public final class ClazzHelper {
    public static boolean clazzImplementsInterface(final Class<?> implementationClazz, final Class<?> interfaceClazz) {
        if (implementationClazz.equals(Object.class)) return false;

        Class<?>[] directInterfaces = implementationClazz.getInterfaces(); // _only_ the direct interfaces, not from super class!
        boolean implementsEvent = Arrays.stream(directInterfaces).toList().contains(interfaceClazz);
        if (implementsEvent) {
            return true;
        }
        else {
            // recursive call
            return clazzImplementsInterface(implementationClazz.getSuperclass(), interfaceClazz);
        }
    }
}
