package cc.smtweb.system.bpm.web.sys.user.dataRightGroup;

import cc.smtweb.framework.core.exception.SwException;
import cc.smtweb.system.bpm.web.common.BpmEnum;
import cc.smtweb.system.bpm.web.sys.user.dataRightGroup.impl.DeptDataRightTreeWork;
import cc.smtweb.system.bpm.web.sys.user.dataRightGroup.impl.PartyDataRightHandler;
import cc.smtweb.system.bpm.web.sys.user.dataRightGroup.impl.PartyDataRightTreeWork;

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

/**
 * @Author yaoq
 * @Date 2022年09月20日 9:26
 * @Description
 */
public class IDataRightTreeFactory {

    private volatile static IDataRightTreeFactory instance = null;

    public static IDataRightTreeFactory getInstance() {
        if (instance == null) {
            synchronized (IDataRightTreeFactory.class) {
                if (instance == null) instance = new IDataRightTreeFactory();
            }
        }
        return instance;
    }

    private Map<String, Class<? extends IDataRightTreeWorker>> mapWorks;
    private Map<String, Class<? extends IDataRightHandler>> mapHandlers;

    private IDataRightTreeFactory() {
        mapWorks = new HashMap<>();
        mapHandlers = new HashMap<>();
        mapWorks.put(BpmEnum.DataRightType.PARTY.value, PartyDataRightTreeWork.class);
        mapHandlers.put(BpmEnum.DataRightType.PARTY.value, PartyDataRightHandler.class);
        mapWorks.put(BpmEnum.DataRightType.DEPT.value, DeptDataRightTreeWork.class);
    }

    public IDataRightTreeWorker getWork(String key) throws Exception {
        Class<? extends IDataRightTreeWorker> cls = mapWorks.get(key);
        if (cls == null) throw new SwException("暂不支持[" + key + "]类型权限！");
        return cls.newInstance();
    }
    public IDataRightHandler getHandler(String key) throws Exception {
        Class<? extends IDataRightHandler> cls = mapHandlers.get(key);
        if (cls == null) throw new SwException("暂不支持[" + key + "]类型权限！");
        return cls.newInstance();
    }
}
