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

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

import com.xisc.pm.app.service.strategy.pdmattype.PdMatTypeStrategy;
import com.xisc.pm.infra.enums.PdMatType;

import io.choerodon.core.exception.CommonException;

/**
 * 组板材料类型策略工厂
 * @author jun.zeng
 *
 */
public class PdMatTypeStrategyFactory {

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

    public static PdMatTypeStrategy matchStrategy(PdMatType matType) {
        return services.get(matType.getCode());
    }
    
    public static PdMatTypeStrategy 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, PdMatTypeStrategy pdMatTypeStrategy) {
        services.put(matType.getCode(), pdMatTypeStrategy);
    }

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