package com.seamew.lottery.domain.award.service.factory;

import com.seamew.lottery.domain.award.annotation.AwardMode;
import com.seamew.lottery.domain.award.service.goods.IDistributionGoods;
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: GoodsConfig
 * @CreateTime: 2023年02月15日 10:59:00
 * @Description: 各类发奖奖品配置类
 * @Version: 1.0
 */
public class GoodsConfig {
    /**
     * 奖品发放策略组
     */
    protected static Map<Integer, IDistributionGoods> goodsMap = new ConcurrentHashMap<>();

    @Resource
    private List<IDistributionGoods> distributionGoodsList = new ArrayList<>();

    @PostConstruct
    public void init() {
        distributionGoodsList.forEach(element -> {
            AwardMode awardMode = AnnotationUtils.findAnnotation(element.getClass(), AwardMode.class);
            if (awardMode != null) {
                goodsMap.put(awardMode.awardMode().getCode(), element);
            }
        });
    }
}
