package com.xisc.pm.app.service.strategy;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.xisc.pm.app.service.strategy.pdrule.RuleExecStrategy;
import com.xisc.pm.infra.enums.PdRuleItemType;

public class RuleExecStrategyFactory {

    private static Map<Long, RuleExecStrategy> services = new ConcurrentHashMap<Long, RuleExecStrategy>();

    public static RuleExecStrategy matchPdEventStrategy(PdRuleItemType ruleItemType) {
        return services.get(ruleItemType.getCode());
    }
    
    public static RuleExecStrategy matchPdRuleStrategy(Long ruleItemType) {
        if(ruleItemType == null) {
            return null;
        }
        return services.get(ruleItemType);
    }

    /**
     * 注册事件策略策略
     * 
     * @param policy
     * @param calcStrategy
     */
    public static void register(PdRuleItemType eventType, RuleExecStrategy pdEventStrategy) {
        services.put(eventType.getCode(), pdEventStrategy);
    }

    /**
     * @return the services
     */
    public static Map<Long, RuleExecStrategy> getServices() {
        return services;
    }
    
}
