package cz.jzitnik.game.mobs;

import cz.jzitnik.game.annotations.EntityLogic;
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;

import java.util.Set;

import static org.junit.jupiter.api.Assertions.*;

class EntityLogicProviderTest {
    @Test
    @DisplayName("All classes annotated with @EntityLogic must implement EntityLogicInterface")
    void allEntityKillImplement() {
        Reflections reflections = new Reflections("cz.jzitnik.game.mobs.services");
        Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(EntityLogic.class);

        for (Class<?> clazz : handlerClasses) {
            boolean implementsClass = EntityLogicInterface.class.isAssignableFrom(clazz);
            assertTrue(implementsClass, "Class " + clazz.getName() + " annotated with @EntityLogic does not implement EntityLogicInterface.");
        }
    }

    @Test
    @DisplayName("Test that entities exists for all entity spawn handlers")
    void allEntitiesExists() {
        EntityLogicProvider entityLogicProvider = new EntityLogicProvider();
        for (String entity : entityLogicProvider.logicList.keySet()) {
            assertDoesNotThrow(() -> ItemBlockSupplier.getEntity(entity),
                    "Entity " + entity + " does not exist but has a logic implemented.");
        }
    }
}
