package cz.jzitnik.game.entities.items;

import cz.jzitnik.game.annotations.BlockRegistry;
import cz.jzitnik.game.annotations.EntityRegistry;
import cz.jzitnik.game.annotations.ItemRegistry;
import cz.jzitnik.game.entities.Block;
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 ItemBlockSupplierTest {
    @Test
    @DisplayName("All classes annotated with @BlockRegistry must extend class Block")
    void allBlocksMustExtendBlock() {
        Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
        Set<Class<?>> blockClasses = reflections.getTypesAnnotatedWith(BlockRegistry.class);

        for (Class<?> clazz : blockClasses) {
            var extendsClass = Block.class.isAssignableFrom(clazz);
            assertTrue(extendsClass, "Class " + clazz.getName() + " annotated with @BlockRegistry does not extend " + Block.class.getName());
        }
    }

    @Test
    @DisplayName("All classes annotated with @EntityRegistry must extend class Block")
    void allEntitiesMustExtendBlock() {
        Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
        Set<Class<?>> blockClasses = reflections.getTypesAnnotatedWith(EntityRegistry.class);

        for (Class<?> clazz : blockClasses) {
            var extendsClass = Block.class.isAssignableFrom(clazz);
            assertTrue(extendsClass, "Class " + clazz.getName() + " annotated with @EntityRegistry does not extend " + Block.class.getName());
        }
    }

    @Test
    @DisplayName("All classes annotated with @ItemRegistry must extend class Item")
    void allItemsMustExtendItem() {
        Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
        Set<Class<?>> blockClasses = reflections.getTypesAnnotatedWith(ItemRegistry.class);

        for (Class<?> clazz : blockClasses) {
            var extendsClass = Item.class.isAssignableFrom(clazz);
            assertTrue(extendsClass, "Class " + clazz.getName() + " annotated with @ItemRegistry does not extend " + Item.class.getName());
        }
    }
}