package cz.jzitnik.game.mobs;

import cz.jzitnik.game.annotations.EntityKillHandler;
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 EntityKillTest {
    @Test
    @DisplayName("All classes annotated with @EntityKillHandler must implement EntityKillInterface")
    void allEntityKillImplement() {
        Reflections reflections = new Reflections("cz.jzitnik.game.mobs.services");
        Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(EntityKillHandler.class);

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

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