// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java
// @Data
// public class Ingredient {
//     private IngredientType type;
//     private Integer quantity;
// 
//     public Ingredient(IngredientType type, Integer quantity) {
//         this.type = type;
//         this.quantity = quantity;
//     }
// 
//     public Ingredient() {
//     }
// }
// 
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java
// public enum IngredientType {
//     MALT, WATER, HOP, YEAST
// }
// 
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java
// @ToString
// public class Ingredients {
// 
//     public Ingredients() {
//     }
// 
//     public Ingredients(Iterable<Ingredient> ingredients) {
//         this.ingredients = Lists.newArrayList(ingredients);
//     }
// 
//     public List<Ingredient> ingredients = Lists.newArrayList();
// 
// }


import io.spring.cloud.samples.brewery.common.model.Ingredient;
import io.spring.cloud.samples.brewery.common.model.IngredientType;
import io.spring.cloud.samples.brewery.common.model.Ingredients;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
package io.spring.cloud.samples.brewery.aggregating;



@Service
class IngredientWarehouse {

    private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>();

    public void addIngredient(Ingredient ingredient) {
        int currentQuantity = DATABASE.getOrDefault(ingredient.getType(), 0);
        DATABASE.put(ingredient.getType(), currentQuantity + ingredient.getQuantity());
    }

    public void useIngredients(Integer amount) {
        DATABASE.forEach((ingredientType, integer) -> DATABASE.put(ingredientType, integer - amount));
    }

    public Ingredients getCurrentState() {
        return new Ingredients(DATABASE
                .entrySet()
                .stream()
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredient.java
// @Data
// public class Ingredient {
//     private IngredientType type;
//     private Integer quantity;
// 
//     public Ingredient(IngredientType type, Integer quantity) {
//         this.type = type;
//         this.quantity = quantity;
//     }
// 
//     public Ingredient() {
//     }
// }
// 
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/IngredientType.java
// public enum IngredientType {
//     MALT, WATER, HOP, YEAST
// }
// 
// Path: common/src/main/java/io/spring/cloud/samples/brewery/common/model/Ingredients.java
// @ToString
// public class Ingredients {
// 
//     public Ingredients() {
//     }
// 
//     public Ingredients(Iterable<Ingredient> ingredients) {
//         this.ingredients = Lists.newArrayList(ingredients);
//     }
// 
//     public List<Ingredient> ingredients = Lists.newArrayList();
// 
// }


// Path: brewing/src/main/java/io/spring/cloud/samples/brewery/aggregating/IngredientWarehouse.java
import io.spring.cloud.samples.brewery.common.model.Ingredient;
import io.spring.cloud.samples.brewery.common.model.IngredientType;
import io.spring.cloud.samples.brewery.common.model.Ingredients;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

package io.spring.cloud.samples.brewery.aggregating;



@Service
class IngredientWarehouse {

    private static final Map<IngredientType, Integer> DATABASE = new ConcurrentHashMap<>();

    public void addIngredient(Ingredient ingredient) {
        int currentQuantity = DATABASE.getOrDefault(ingredient.getType(), 0);
        DATABASE.put(ingredient.getType(), currentQuantity + ingredient.getQuantity());
    }

    public void useIngredients(Integer amount) {
        DATABASE.forEach((ingredientType, integer) -> DATABASE.put(ingredientType, integer - amount));
    }

    public Ingredients getCurrentState() {
        return new Ingredients(DATABASE
                .entrySet()
                .stream()
                .map((entry) -> new Ingredient(entry.getKey(), entry.getValue()))