package org.dromara.zhishu.service.factory;

import org.dromara.zhishu.service.strategy.InventorySynchronizedGFtrategy;
import org.dromara.zhishu.service.strategy.InventorySynchronizedKWStrategy;
import org.dromara.zhishu.service.strategy.InventorySynchronizedPddStrategy;
import org.dromara.zhishu.service.strategy.InventorySynchronizedStrategy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class InventorySynchronizedStrategyFactory implements ApplicationContextAware {

    private static ApplicationContext context;

    private static final Map<String, Class<? extends InventorySynchronizedStrategy>> strategyClasses = new HashMap<>();

    static {
        // 可以继续添加其他的消息类型对应的策略
        strategyClasses.put("1", InventorySynchronizedPddStrategy.class);
        strategyClasses.put("2", InventorySynchronizedKWStrategy.class);
        strategyClasses.put("5", InventorySynchronizedGFtrategy.class);
    }

    public static InventorySynchronizedStrategy getStrategy(String type) {
        Class<? extends InventorySynchronizedStrategy> strategyClass = strategyClasses.get(type);
        if (strategyClass != null) {
            return context.getBean(strategyClass);
        }
        return null;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        context = applicationContext;
    }
}