"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EvaluateJavaScriptStep = void 0;
exports.isEvaluateJavaScriptStep = isEvaluateJavaScriptStep;
const MablStepV2_1 = require("../MablStepV2");
const JavaScriptAction_1 = require("../actions/JavaScriptAction");
const STEP_NAME = 'EvaluateJavaScript';
class EvaluateJavaScriptStep extends MablStepV2_1.MablStepV2 {
    static stepName = STEP_NAME;
    static actionCode = 'evaluate_js';
    static mablScriptStepNames = [JavaScriptAction_1.JavaScriptAction.mablscriptName];
    static yamlMablScriptNames = [STEP_NAME];
    evaluateJsAction;
    constructor(descriptor) {
        super(EvaluateJavaScriptStep.stepName, descriptor, EvaluateJavaScriptStep.actionCode);
        this.evaluateJsAction = JavaScriptAction_1.JavaScriptAction.fromDescriptor(descriptor);
        this.actions = [this.evaluateJsAction];
    }
    getStepName() {
        return EvaluateJavaScriptStep.stepName;
    }
    static fromYaml(_stepName, stepArgs) {
        const evaluateJsAction = JavaScriptAction_1.JavaScriptAction.fromYaml(stepArgs);
        const actionDescriptor = evaluateJsAction.toDescriptor();
        const stepDescriptor = {
            ...stepArgs,
            ...actionDescriptor,
            id: stepArgs.id,
        };
        return new EvaluateJavaScriptStep(stepDescriptor);
    }
    static fromLegacyMablscript(args, actions) {
        const evaluateJsAction = new JavaScriptAction_1.JavaScriptAction(JavaScriptAction_1.JavaScriptAction.mablscriptName, args);
        const stepDescriptor = evaluateJsAction.toDescriptor();
        const step = new EvaluateJavaScriptStep(stepDescriptor);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        return this.evaluateJsAction.toMablscript();
    }
    getInputVariables() {
        return this.evaluateJsAction.getInputVariables();
    }
    stepDescription() {
        return 'Evaluate JavaScript';
    }
    static create(descriptor) {
        descriptor.id = descriptor.id ?? MablStepV2_1.MablStepV2.generateStepId();
        return new EvaluateJavaScriptStep(descriptor);
    }
}
exports.EvaluateJavaScriptStep = EvaluateJavaScriptStep;
function isEvaluateJavaScriptStep(value) {
    return value?.getStepName && value?.getStepName() === STEP_NAME;
}
