package com.red.circle.other.app.listener.gift.strategy;

import com.red.circle.mq.business.model.event.gift.OfflineStatisticsGiftEventType;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.stereotype.Component;

;

/**
 * 策略工厂.
 *
 * @author pengliang on 2022/7/26
 */
@Component
public class FactoryForGiftStrategy {

  private final Map<String, GiftStrategy> giftStrategyMap = new ConcurrentHashMap<>();

  public FactoryForGiftStrategy(Map<String, GiftStrategy> strategyMap) {
    giftStrategyMap.putAll(strategyMap);
  }

  public GiftStrategy getStrategy(OfflineStatisticsGiftEventType eventType) {
    GiftStrategy strategy = giftStrategyMap.get(eventType.name().concat("_LISTENER"));
    if (strategy == null) {
      throw new IllegalArgumentException("no strategy defined:" + eventType);
    }
    return strategy;
  }

}
