package com.red.circle.order.app.command.pay.app.strategy.extract;

import com.red.circle.tool.core.exception.NotFoundStrategyException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.stereotype.Service;

/**
 * 单据提取策略工厂.
 *
 * @author pengliang on 2020/7/23
 */
@Service
public class FactoryForExtractAppPurchaseOrderStrategy {

  private final Map<String, ExtractAppPurchaseOrderStrategy> strategyCurrentMap = new ConcurrentHashMap<>();

  public FactoryForExtractAppPurchaseOrderStrategy(
      Map<String, ExtractAppPurchaseOrderStrategy> strategyMap) {
    strategyCurrentMap.putAll(strategyMap);
  }

  public ExtractAppPurchaseOrderStrategy getStrategy(String strategyName) {
    ExtractAppPurchaseOrderStrategy strategy = strategyCurrentMap.get(strategyName);
    if (strategy == null) {
      throw new NotFoundStrategyException("no strategy defined", strategyName);
    }
    return strategy;
  }
}
