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

import com.xisc.pm.app.service.strategy.processgenerate.ProcessGenerateStrategy;
import com.xisc.pm.infra.enums.PdProcessType;

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

/**
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @date 2024/12/17 8:48
 * @description
 */
public class ProcessGenerateStrategyFactory {
    private static Map<String, ProcessGenerateStrategy> services = new ConcurrentHashMap<String, ProcessGenerateStrategy>();

    public static ProcessGenerateStrategy matchProcessStrategy(PdProcessType pdProcessType) {
        if (pdProcessType == null) {
            return null;
        }
        return services.get(pdProcessType.getCode());
    }

    public static ProcessGenerateStrategy matchProcessStrategy(String code) {
        return services.get(code);
    }

    /**
     * 注册事件策略策略
     *
     * @param pdProcessType
     * @param processGenerateStrategy
     */
    public static void register(PdProcessType pdProcessType, ProcessGenerateStrategy processGenerateStrategy) {
        services.put(pdProcessType.getCode(), processGenerateStrategy);
    }

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