package com.ningdatech.pmapi.common.statemachine.factory;

import com.ningdatech.pmapi.common.constant.StateMachineConst;
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import org.springframework.statemachine.StateContext;
import org.springframework.statemachine.guard.Guard;

/**
 * 项目申报状态机guard集合类
 *
 * @author CMM
 * @since 2023/02/07 16:18
 */

public class ProjectDeclareGuardFactory {
    private static final String PROJECT_DECLARE = StateMachineConst.PROJECT_DECLARE;

    public class PendingPreQualificationChoiceGuard implements Guard<ProjectStatusEnum, ProjectStatusChangeEvent> {
        @Override
        public boolean evaluate(StateContext<ProjectStatusEnum, ProjectStatusChangeEvent> context) {
            Project project = context.getMessage().getHeaders().get(PROJECT_DECLARE, Project.class);
            // 判断申报项目是否是市级项目，且申报金额是否大于等于1000万元
            if (StateMachineUtils.isCityProject(project) && StateMachineUtils.judgeDeclareAmount(project)){
                return true;
            }
            return false;
        }
    }
}
