package cn.stylefeng.workflow.instance.modular.task.strategy.agree.base;

import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.workflow.api.entity.task.RuTask;
import cn.stylefeng.workflow.api.enums.ApproverNodeTypeEnum;
import cn.stylefeng.workflow.api.pojo.config.node.approver.ApproverStrategy;
import cn.stylefeng.workflow.instance.modular.task.service.RuTaskService;
import cn.stylefeng.workflow.instance.modular.task.strategy.agree.BaseAgreeStrategy;

public class AgreeOrStrategy implements BaseAgreeStrategy {

    private final boolean purePredictFlag;

    public AgreeOrStrategy(boolean purePredictFlag) {
        this.purePredictFlag = purePredictFlag;
    }

    @Override
    public boolean getStrategyExecuteFlag(Integer approverNodeTypeEnum) {
        return ApproverNodeTypeEnum.OR_APPROVE.getMode().equals(approverNodeTypeEnum);
    }

    @Override
    public boolean strategyAction(RuTask currentProcessTask, ApproverStrategy approverStrategy) {


        RuTaskService ruTaskService = SpringUtil.getBean(RuTaskService.class);
        ruTaskService.deleteAnyOtherTask(!purePredictFlag, currentProcessTask.getRuNodeId(), currentProcessTask.getTaskId());

        return true;
    }

}
