package thb.jeanluc.adventure.loader;

import org.junit.jupiter.api.Test;
import thb.jeanluc.adventure.game.Combinations;
import thb.jeanluc.adventure.game.GameContext;
import thb.jeanluc.adventure.game.GameSession;
import thb.jeanluc.adventure.io.TestIO;
import thb.jeanluc.adventure.model.Combination;

import static org.assertj.core.api.Assertions.assertThat;

class CombinationLoadingTest {

    @Test
    void realWorldLoadsTheTorchRecipe() {
        WorldLoader.LoadResult loaded = new WorldLoader().load();
        assertThat(loaded.world().getCombinations())
                .containsKey(Combination.key("matches", "torch"));
        assertThat(loaded.world().getItems()).containsKeys("matches", "torch", "lit_torch");
    }

    @Test
    void torchRecipeWorksEndToEnd() {
        WorldLoader.LoadResult loaded = new WorldLoader().load();
        GameContext ctx = new GameContext(
                new GameSession(loaded.world(), loaded.player(), "test"), new TestIO());
        // grab the demo items straight from the registry, regardless of room
        ctx.getPlayer().addItem(ctx.getWorld().getItems().get("matches"));
        ctx.getPlayer().addItem(ctx.getWorld().getItems().get("torch"));
        Combinations.tryUse(ctx, "matches", "torch");
        assertThat(ctx.getPlayer().hasItem("lit_torch")).isTrue();
    }
}
