// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/ShopTransaction.java
// public class ShopTransaction {
//     private final Currency currency;
//     // Direction is always what the player is doing. BUY = player is buying from shop.
//     private final TransactionDirection direction;
//     private final Player player;
//     private final ItemInfo item;
//     private final int quantity;
//     private final BigDecimal price;
// 
//     public ShopTransaction(Currency currency, TransactionDirection direction, Player player, ItemInfo item, int quantity, BigDecimal price) {
//         this.currency = currency;
//         this.direction = direction;
//         this.player = player;
//         this.item = item;
//         this.quantity = quantity;
//         this.price = price;
//     }
// 
//     public TransactionDirection getDirection() {
//         return this.direction;
//     }
// 
//     public Player getPlayer() {
//         return this.player;
//     }
// 
//     public ItemInfo getItem() {
//         return this.item;
//     }
// 
//     public int getQuantity() {
//         return this.quantity;
//     }
// 
//     public BigDecimal getPrice() {
//         return this.price;
//     }
// 
//     public Transaction makeEconomyTransaction() {
//         if (this.direction == TransactionDirection.BUY) {
//             return new Transaction(this.currency, Economable.wrap(this.player), Economable.PLUGIN, this.price, TransactionReason.PLUGIN_TAKE);
//         } else {
//             return new Transaction(this.currency, Economable.PLUGIN, Economable.wrap(this.player), this.price, TransactionReason.PLUGIN_GIVE);
//         }
//     }
// 
//     public enum TransactionDirection {
//         BUY, SELL
//     }
// }
// 
// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/ShopTransaction.java
// public enum TransactionDirection {
//     BUY, SELL
// }
// 
// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/ItemDatabase.java
// public static class InvalidItemException extends Exception {
//     public InvalidItemException(String message) {
//         super(message);
//     }
// }


import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
import org.appledash.saneeconomysignshop.util.ItemDatabase.InvalidItemException;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
    public boolean shouldAllowTransaction(ShopTransaction transaction) {
        // System.out.printf("Limit: %d, quantity: %d\n", limit, transaction.getQuantity());
        return this.getRemainingLimit(transaction.getPlayer(), transaction.getDirection(), transaction.getItem()) >= transaction.getQuantity();
    }

    public void incrementLimitsHourly() {
        // For every limit type
        // For every player
        // For every limit
        // Increment limit by the limit for the specific direction and item.

        this.sellPlayerLimits.forEach((playerUuid, itemToLimit) -> {
            Map<ItemInfo, Integer> newLimits = new HashMap<>();

            itemToLimit.forEach((itemInfo, currentLimit) ->
                                newLimits.put(itemInfo, currentLimit + (this.sellItemLimits.get(itemInfo).getHourlyGain())));

            itemToLimit.putAll(newLimits);
        });
    }

    public void loadLimits(ConfigurationSection config) {
        for (Map<?, ?> map : config.getMapList("sell")) {
            String itemName = String.valueOf(map.get("item"));
            int sellLimit = Integer.parseInt(String.valueOf(map.get("limit")));
            int hourlyGain = Integer.parseInt(String.valueOf(map.get("gain")));
            ItemStack stack;

            try {
                stack = ItemDatabase.parseGive(itemName);
// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/ShopTransaction.java
// public class ShopTransaction {
//     private final Currency currency;
//     // Direction is always what the player is doing. BUY = player is buying from shop.
//     private final TransactionDirection direction;
//     private final Player player;
//     private final ItemInfo item;
//     private final int quantity;
//     private final BigDecimal price;
// 
//     public ShopTransaction(Currency currency, TransactionDirection direction, Player player, ItemInfo item, int quantity, BigDecimal price) {
//         this.currency = currency;
//         this.direction = direction;
//         this.player = player;
//         this.item = item;
//         this.quantity = quantity;
//         this.price = price;
//     }
// 
//     public TransactionDirection getDirection() {
//         return this.direction;
//     }
// 
//     public Player getPlayer() {
//         return this.player;
//     }
// 
//     public ItemInfo getItem() {
//         return this.item;
//     }
// 
//     public int getQuantity() {
//         return this.quantity;
//     }
// 
//     public BigDecimal getPrice() {
//         return this.price;
//     }
// 
//     public Transaction makeEconomyTransaction() {
//         if (this.direction == TransactionDirection.BUY) {
//             return new Transaction(this.currency, Economable.wrap(this.player), Economable.PLUGIN, this.price, TransactionReason.PLUGIN_TAKE);
//         } else {
//             return new Transaction(this.currency, Economable.PLUGIN, Economable.wrap(this.player), this.price, TransactionReason.PLUGIN_GIVE);
//         }
//     }
// 
//     public enum TransactionDirection {
//         BUY, SELL
//     }
// }
// 
// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/signshop/ShopTransaction.java
// public enum TransactionDirection {
//     BUY, SELL
// }
// 
// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/ItemDatabase.java
// public static class InvalidItemException extends Exception {
//     public InvalidItemException(String message) {
//         super(message);
//     }
// }


// Path: SaneEconomySignShop/src/main/java/org/appledash/saneeconomysignshop/util/LimitManager.java
import org.appledash.saneeconomysignshop.signshop.ShopTransaction;
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
import org.appledash.saneeconomysignshop.util.ItemDatabase.InvalidItemException;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;

    public boolean shouldAllowTransaction(ShopTransaction transaction) {
        // System.out.printf("Limit: %d, quantity: %d\n", limit, transaction.getQuantity());
        return this.getRemainingLimit(transaction.getPlayer(), transaction.getDirection(), transaction.getItem()) >= transaction.getQuantity();
    }

    public void incrementLimitsHourly() {
        // For every limit type
        // For every player
        // For every limit
        // Increment limit by the limit for the specific direction and item.

        this.sellPlayerLimits.forEach((playerUuid, itemToLimit) -> {
            Map<ItemInfo, Integer> newLimits = new HashMap<>();

            itemToLimit.forEach((itemInfo, currentLimit) ->
                                newLimits.put(itemInfo, currentLimit + (this.sellItemLimits.get(itemInfo).getHourlyGain())));

            itemToLimit.putAll(newLimits);
        });
    }

    public void loadLimits(ConfigurationSection config) {
        for (Map<?, ?> map : config.getMapList("sell")) {
            String itemName = String.valueOf(map.get("item"));
            int sellLimit = Integer.parseInt(String.valueOf(map.get("limit")));
            int hourlyGain = Integer.parseInt(String.valueOf(map.get("gain")));
            ItemStack stack;

            try {
                stack = ItemDatabase.parseGive(itemName);
            } catch (InvalidItemException e) {