package thb.jeanluc.adventure.game;

import org.junit.jupiter.api.Test;
import thb.jeanluc.adventure.io.TestIO;
import thb.jeanluc.adventure.model.Condition;
import thb.jeanluc.adventure.model.Player;
import thb.jeanluc.adventure.model.Room;
import thb.jeanluc.adventure.model.item.PlainItem;

import java.util.List;

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

class ConditionsTest {
    private GameContext ctx() {
        Player p = new Player(new Room("k", "K", "d"), 0);
        return new GameContext(null, p, new TestIO());
    }

    @Test
    void flagAndNotFlag() {
        GameContext ctx = ctx();
        ctx.getState().set("power_on");
        assertThat(Conditions.holds(new Condition(Condition.Type.FLAG, "power_on"), ctx)).isTrue();
        assertThat(Conditions.holds(new Condition(Condition.Type.NOT_FLAG, "power_on"), ctx)).isFalse();
        assertThat(Conditions.holds(new Condition(Condition.Type.NOT_FLAG, "x"), ctx)).isTrue();
    }

    @Test
    void hasItem() {
        GameContext ctx = ctx();
        ctx.getPlayer().addItem(PlainItem.builder().id("lamp").name("Lamp").description("d").build());
        assertThat(Conditions.holds(new Condition(Condition.Type.HAS_ITEM, "lamp"), ctx)).isTrue();
        assertThat(Conditions.holds(new Condition(Condition.Type.HAS_ITEM, "key"), ctx)).isFalse();
    }

    @Test
    void allRequiresEveryConditionAndEmptyIsTrue() {
        GameContext ctx = ctx();
        ctx.getState().set("a");
        assertThat(Conditions.all(List.of(), ctx)).isTrue();
        assertThat(Conditions.all(List.of(new Condition(Condition.Type.FLAG, "a")), ctx)).isTrue();
        assertThat(Conditions.all(List.of(
                new Condition(Condition.Type.FLAG, "a"),
                new Condition(Condition.Type.FLAG, "b")), ctx)).isFalse();
    }
}
