"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetVariableValue = void 0;
const MablAction_1 = require("../MablAction");
const MablSymbol_1 = require("../MablSymbol");
const GetVariableDescriptor_1 = require("../types/GetVariableDescriptor");
class GetVariableValue extends MablAction_1.MablAction {
    static actionCode = 'get_variable_value';
    static mablScriptStepNames = [GetVariableValue.actionCode];
    static yamlMablScriptNames = [GetVariableDescriptor_1.GET_VARIABLE_VALUE];
    variable;
    constructor(name, args) {
        super(name, 'get_variable_value', args);
        const arg = this.getActionArgs()[0];
        if ((0, MablSymbol_1.isMablSymbolObject)(arg)) {
            this.variable = new MablSymbol_1.MablSymbol(arg.name);
        }
        else if (typeof arg === 'string') {
            const legacyPatternMatches = arg.match(MablSymbol_1.SINGLE_VARIABLE_PATTERN_REGEX);
            if (legacyPatternMatches) {
                this.variable = new MablSymbol_1.MablSymbol(legacyPatternMatches[1]);
            }
            else {
                this.variable = new MablSymbol_1.MablSymbol(arg);
            }
        }
        else {
            this.variable = new MablSymbol_1.MablSymbol(arg);
        }
    }
    static buildAction(variable) {
        const variableName = typeof variable === 'string' ? variable : variable.name;
        return new GetVariableValue(GetVariableValue.actionCode, [variableName]);
    }
    toMablscript() {
        return `get_variable_value(${this.subVariable(this.variable.toString())})`;
    }
    toDescriptor() {
        return { kind: GetVariableDescriptor_1.GET_VARIABLE_VALUE, variable: this.variable.name };
    }
    generateFindMablscript() {
        return `get_variable_value(${this.variable.name})`;
    }
    getInputVariables() {
        return MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.variable);
    }
}
exports.GetVariableValue = GetVariableValue;
