package thb.jeanluc.adventure.command.impl;

import thb.jeanluc.adventure.game.GameContext;
import thb.jeanluc.adventure.io.TestIO;
import thb.jeanluc.adventure.model.Direction;
import thb.jeanluc.adventure.model.Npc;
import thb.jeanluc.adventure.model.NpcReaction;
import thb.jeanluc.adventure.model.Player;
import thb.jeanluc.adventure.model.Room;
import thb.jeanluc.adventure.model.item.Item;
import thb.jeanluc.adventure.model.item.PlainItem;
import thb.jeanluc.adventure.model.item.ReadableItem;
import thb.jeanluc.adventure.model.item.SwitchableItem;

/**
 * Tiny world used by the command tests. Two rooms (kitchen → hallway),
 * a few items, and one NPC with one reaction.
 */
public final class CommandTestSupport {

    private CommandTestSupport() {}

    public static class World {
        public final Room kitchen;
        public final Room hallway;
        public final Item lamp;
        public final Item letter;
        public final Item key;
        public final Item shovel;
        public final Npc oldMan;
        public final Player player;
        public final TestIO io = new TestIO();
        public final GameContext ctx;

        public World() {
            kitchen = new Room("kitchen", "Kitchen", "kitchen desc");
            hallway = new Room("hallway", "Hallway", "hallway desc");
            kitchen.addExit(Direction.NORTH, hallway);
            hallway.addExit(Direction.SOUTH, kitchen);

            lamp = SwitchableItem.builder().id("lamp").name("Lamp").description("a lamp")
                    .state(false).onText("on").offText("off").build();
            letter = ReadableItem.builder().id("letter").name("Letter").description("a letter")
                    .readText("dear reader").build();
            key = PlainItem.builder().id("key").name("Key").description("brass key").build();
            shovel = PlainItem.builder().id("shovel").name("Shovel").description("rusty").build();

            kitchen.addItem(lamp);
            kitchen.addItem(letter);

            oldMan = Npc.shell("old_man", "Old Man", "stooped", "greetings");
            oldMan.putReaction("lamp", NpcReaction.builder()
                    .consumes(lamp).gives(key).response("Take the key.").build());
            kitchen.addNpc(oldMan);

            player = new Player(kitchen, 0);
            ctx = new GameContext(null, player, io);
        }
    }
}
