package com.seamew.lottery.domain.strategy.service.draw;

import com.seamew.lottery.domain.strategy.annotation.StrategyMode;
import com.seamew.lottery.domain.strategy.service.algorithm.IDrawAlgorithm;
import org.springframework.core.annotation.AnnotationUtils;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: seamew
 * @Title: DrawConfig
 * @CreateTime: 2023年02月13日 21:00:00
 * @Description: 抽奖统一配置信息类
 * @Version: 1.0
 */
public class DrawConfig {

    protected static Map<Integer, IDrawAlgorithm> drawAlgorithmGroup = new ConcurrentHashMap<>();

    @Resource
    private List<IDrawAlgorithm> algorithmList = new ArrayList<>();


    @PostConstruct
    public void init() {
        algorithmList.forEach(element -> {
            StrategyMode strategyMode = AnnotationUtils.findAnnotation(element.getClass(), StrategyMode.class);
            if (strategyMode != null) {
                drawAlgorithmGroup.put(strategyMode.strategyMode().getCode(), element);
            }
        });
    }
}
