package cn.stylefeng.workflow.rule.api.condition;

import cn.stylefeng.workflow.api.pojo.InstanceContext;
import lombok.Getter;
import lombok.Setter;
import org.jeasy.rules.api.Facts;

@Getter
@Setter
public abstract class BaseWorkflowRule<T> extends BaseRule<T> {

    public static final String DECISION_FACTS_INSTANCE_CONTEXT = "instanceContext";

    T result;

    public abstract boolean workflowEvaluate(InstanceContext instanceContext);

    public abstract void workflowExecute(InstanceContext instanceContext);

    public abstract String getBaseRuleName();

    public abstract int getBaseRulePriority();

    @Override
    public int getPriority() {
        return this.getBaseRulePriority();
    }

    @Override
    public String getName() {
        return this.getBaseRuleName();
    }

    @Override
    public boolean evaluate(Facts facts) {
        InstanceContext instanceContext = facts.get(DECISION_FACTS_INSTANCE_CONTEXT);
        return this.workflowEvaluate(instanceContext);
    }

    @Override
    public void execute(Facts facts) throws Exception {
        InstanceContext instanceContext = facts.get(DECISION_FACTS_INSTANCE_CONTEXT);
        this.workflowExecute(instanceContext);
    }

}
