package thb.jeanluc.adventure.command.impl;

import thb.jeanluc.adventure.command.Command;
import thb.jeanluc.adventure.game.GameContext;
import thb.jeanluc.adventure.model.item.Item;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Lists the items the player is currently carrying.
 * Usage: {@code inventory}.
 */
public class InventoryCommand implements Command {

    @Override
    public void execute(GameContext ctx, List<String> args) {
        var inventory = ctx.getPlayer().getInventory();
        if (inventory.isEmpty()) {
            ctx.getIo().write("You are not carrying anything.");
            return;
        }
        String list = inventory.values().stream()
                .map(Item::getName)
                .collect(Collectors.joining(", "));
        ctx.getIo().write("You are carrying: " + list + ".");
    }

    @Override
    public String help() {
        return "inventory  -  list what you are carrying (alias: inv, i)";
    }
}
