package website.automate.jwebrobot.expression.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import website.automate.jwebrobot.context.ScenarioExecutionContext;
import website.automate.jwebrobot.expression.ExpressionEvaluator;
import website.automate.waml.io.model.main.action.DefineAction;

import java.util.Map;

@Service
public class DefineActionExpressionEvaluator extends ConditionalActionExpressionEvaluator<DefineAction> {

    @Autowired
    public DefineActionExpressionEvaluator(
            ExpressionEvaluator expressionEvaluator) {
        super(expressionEvaluator);
    }

    @Override
    public void evaluate(DefineAction action, ScenarioExecutionContext context) {
        super.evaluate(action, context);

        Map<String, Object> facts = action.getDefine().getFacts();
        facts.keySet()
            .stream()
            .map(key -> evaluateAsString(key, context));
        facts.values()
            .stream()
            .forEach(value -> evaluateIfExpression(value, context));
    }

    private Object evaluateIfExpression(Object value, ScenarioExecutionContext context){
        if(value instanceof String){
            String valueStr = String.class.cast(value);
            return evaluateAsObject(valueStr, context);
        }
        return value;
    }

    @Override
    public Class<DefineAction> getSupportedType() {
        return DefineAction.class;
    }
}

@@ -871,176 +871,90 @@
    f
-acts.keySet()%0A            .stream()%0A            .map(key -%3E evaluateAsString(key, context));%0A        facts.values()%0A            .stream()%0A            .forEach(value -%3E 
+or(Map.Entry%3CString, Object%3E entry: facts.entrySet())%7B%0A            entry.setValue(
 eval
@@ -970,21 +970,32 @@
 ression(
-v
+entry.getV
 alue
+()
 , contex
@@ -999,16 +999,26 @@
 text));%0A
+        %7D%0A
     %7D%0A%0A 

Fix define value evaluation