package cz.jzitnik.game.handlers.pickup;

import cz.jzitnik.game.annotations.PickupHandler;
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 PickupHandlerProviderTest {
    @Test
    @DisplayName("All classes annotated with @PickupHandler must implement CustomPickupHandler")
    void allClassesPickupImplementHandler() {
        Reflections reflections = new Reflections("cz.jzitnik.game.handlers.pickup.handlers");
        Set<Class<?>> handlerClasses = reflections.getTypesAnnotatedWith(PickupHandler.class);

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

    @Test
    @DisplayName("All items in annotation @PickupHandler must exist")
    void allBlocksMustExist() {
        PickupHandlerProvider pickupHandlerProvider = new PickupHandlerProvider();

        for (String id : pickupHandlerProvider.pickupList.keySet()) {
            assertDoesNotThrow(() -> ItemBlockSupplier.getItem(id), "Item " + id + " does not exist but is in annotation @PickupHandler");
        }
    }
}