package com.hz.pm.api.staging.utils;

import com.google.common.collect.Maps;
import com.hz.pm.api.projectdeclared.manage.ReviewByDeptJointManage;
import com.hz.pm.api.projectdeclared.manage.ReviewByProvincialDeptManage;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.projectlib.model.enumeration.ProjectStatusEnum;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.function.Function;

/**
 * @Classname ProjectStatusFlowMapUtil
 * @Description 状态流转 事件函数MAP
 * @Date 2023/2/15 11:19
 * @Author PoffyZhang
 */
@Component
public class ProjectStatusFlowMapUtil {

    private static final Map<Integer, Function<Project, Boolean>> STATUS_FLOW_FUNCTION_MAP = Maps.newHashMap();


    public static Function<Project, Boolean> getFlowFunction(Integer status){
        return STATUS_FLOW_FUNCTION_MAP.get(status);
    }

    /**
     * 初始化业务分派逻辑,代替了if-else部分
     * key: 枚举 状态值
     * value: lambda表达式,最终会获取发起实例的函数
     */
    public ProjectStatusFlowMapUtil(ReviewByProvincialDeptManage provincialDeptManage,
                                    ReviewByDeptJointManage reviewByDeptJointManage) {
        //省级部门联审
        STATUS_FLOW_FUNCTION_MAP.put(ProjectStatusEnum.JOINT_REVIEW_BY_PROVINCIAL_DEPARTMENTS.getCode(),
                provincialDeptManage::startTheProcess);
        //部门联审
        STATUS_FLOW_FUNCTION_MAP.put(ProjectStatusEnum.DEPARTMENT_JOINT_REVIEW.getCode(),
                reviewByDeptJointManage::startTheProcess);
    }

}
