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

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

import com.xisc.pm.app.service.strategy.secondarydesign.SecondaryDesignStrategy;
import com.xisc.pm.infra.enums.PdMatType;

import io.choerodon.core.exception.CommonException;

/**
 * 二次设计策略工厂类
 * @author jun.zeng
 *
 */
public class SecondaryDesignStrategyFactory {

    private static Map<String, SecondaryDesignStrategy> services = new ConcurrentHashMap<String, SecondaryDesignStrategy>();

    public static SecondaryDesignStrategy matchStrategy(PdMatType matType) {
        return services.get(matType.getCode());
    }
    
    public static SecondaryDesignStrategy matchStrategy(String code) {
        if(!services.containsKey(code)) {
            throw new CommonException("pm.pm_pro_cont_049" , code);
        }
        return services.get(code);
    }

    /**
     * 注册事件策略策略
     * 
     * @param policy
     * @param calcStrategy
     */
    public static void register(PdMatType matType, SecondaryDesignStrategy pdMatTypeStrategy) {
        services.put(matType.getCode(), pdMatTypeStrategy);
    }

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