package cz.jzitnik.game.mobs;

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

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

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