package cn.stylefeng.workflow.instance.core.condition.base;

import cn.stylefeng.workflow.api.pojo.InstanceContext;
import cn.stylefeng.workflow.api.pojo.config.node.approver.ApproverConfig;
import cn.stylefeng.workflow.rule.api.condition.BaseWorkflowRule;
import org.jeasy.rules.api.Facts;

import java.util.List;

public abstract class BaseApproverRule extends BaseWorkflowRule<List<Long>> {

    public static final String DECISION_FACTS_NODE_APPROVER = "nodeApprover";

    public abstract boolean approverEvaluate(InstanceContext instanceContext, ApproverConfig approverConfig);

    public abstract void approverExecute(InstanceContext instanceContext, ApproverConfig approverConfig);

    @Override
    public boolean workflowEvaluate(InstanceContext instanceContext) {

        return false;
    }

    @Override
    public void workflowExecute(InstanceContext instanceContext) {

    }

    @Override
    public boolean evaluate(Facts facts) {
        InstanceContext instanceContext = facts.get(DECISION_FACTS_INSTANCE_CONTEXT);
        ApproverConfig approverConfig = facts.get(DECISION_FACTS_NODE_APPROVER);
        return this.approverEvaluate(instanceContext, approverConfig);
    }

    @Override
    public void execute(Facts facts) throws Exception {
        InstanceContext instanceContext = facts.get(DECISION_FACTS_INSTANCE_CONTEXT);
        ApproverConfig approverConfig = facts.get(DECISION_FACTS_NODE_APPROVER);
        this.approverExecute(instanceContext, approverConfig);
    }

}
