package cz.jzitnik.game;

import cz.jzitnik.tui.Sprite;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import static org.junit.jupiter.api.Assertions.*;

public class SpriteLoaderTest {
    @Test
    @DisplayName("Verify all SPRITES enum values are present in SPRITES_MAP")
    void testAllSpritesArePresent() {
        for (SpriteLoader.SPRITES spriteEnum : SpriteLoader.SPRITES.values()) {
            assertTrue(SpriteLoader.SPRITES_MAP.containsKey(spriteEnum), "Missing sprite: " + spriteEnum);
            assertNotNull(SpriteLoader.SPRITES_MAP.get(spriteEnum), "Sprite is null: " + spriteEnum);
        }
    }

    @Test
    @DisplayName("Ensure that for each sprite all the resources are present.")
    void testAllResourcesArePresent() {
        for (SpriteLoader.SPRITES spriteEnum : SpriteLoader.SPRITES_MAP.keySet()) {
            Sprite sprite = SpriteLoader.SPRITES_MAP.get(spriteEnum);
            assertNotNull(sprite.getSprite(), "getSprite() couldn't find file for: " + spriteEnum);

            if (sprite.getStates().isPresent()) {
                for (Enum state : ((Class<Enum>) SpriteLoader.SPRITES_MAP.get(spriteEnum).getStates().get())
                        .getEnumConstants()) {
                    assertNotNull(SpriteLoader.SPRITES_MAP.get(spriteEnum).getSprite(state),
                            "getSprite(" + state + ") couldn't find file for: " + spriteEnum);
                }
            }

        }
    }
}
