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

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

/**
 * web支付策略.
 *
 * @author pengliang on 2022/11/02
 */
@Service
public class FactoryPlaceAnOrderStrategyV2 {

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

  public FactoryPlaceAnOrderStrategyV2(Map<String, PayWebPlaceAnOrderStrategyV2> strategyMap) {
    strategyCurrentMap.putAll(strategyMap);
  }

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