import CommandBuilder from "../builders/command";

function inventoryHandler(args, context) {
    const items = context.player.getInventory();
    if (items.length < 1) return context.print(`You're not carrying anything.`);
    let itemDescription = `You are carrying `;
    items.forEach((item, index) => {
        if (index < items.length - 2) {
            itemDescription += `${item.name}, `;
        } else if (index < items.length - 1) {
            itemDescription += `${item.name} and `;
        } else {
            itemDescription += item.name
        }
    });
    context.print(itemDescription + ".");
}

export default new CommandBuilder()
    .withName("inventory")
    .withAliases(["i", "inv"])
    .withCategory("Actions")
    .withDescription("View inventory")
    .withHandler(inventoryHandler)
    .create();