package com.ningdatech.pmapi.staging.utils;

import com.google.common.collect.Maps;
import com.ningdatech.pmapi.projectdeclared.manage.*;
import com.ningdatech.pmapi.projectdeclared.model.dto.DefaultDeclaredDTO;
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.staging.model.entity.ProjectStaging;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
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 {
    @Autowired
    private ReviewByProvincialDeptManage provincialDeptManage;

    @Autowired
    private ReviewByDeptJointManage reviewByDeptJointManage;

    public Map<Integer, Function<Project,Boolean>> statusFlowFunctionMap = Maps.newHashMap();
    /**
     * key 重试的次数 , value 是增加是描述
     */
    public Map<Integer, Integer> intervalTimeMap = Maps.newHashMap();

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


    /**
     *  扫描的间隔越来越长 秒数
     */
    @PostConstruct
    public void intervalTimeMapInit(){
        intervalTimeMap.put(1,60 * 2);
        intervalTimeMap.put(2,60 * 6);
        intervalTimeMap.put(3,60 * 15);
        intervalTimeMap.put(4,60 * 30);
        intervalTimeMap.put(5,60 * 60);
        intervalTimeMap.put(6,60 * 60 * 2);
        intervalTimeMap.put(7,60 * 60 * 5);
        intervalTimeMap.put(8,60 * 60 * 12);
        intervalTimeMap.put(9,60 * 60 * 24);
        intervalTimeMap.put(10,60 * 60 * 72);
    }
}
