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

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/22
 */
@Service
public class FactoryForAppleServerToServerStrategy {

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

  public FactoryForAppleServerToServerStrategy(
      Map<String, AppleServerToServerStrategy> strategyMap) {
    strategyMap.forEach(strategyCurrentMap::put);
  }

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

}
