"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatabaseQueryVariableSource = exports.DatabaseQueryStep = void 0;
exports.isDatabaseQueryStep = isDatabaseQueryStep;
const AbstractAssertionsAndVariablesStep_1 = require("./AbstractAssertionsAndVariablesStep");
class DatabaseQueryStep extends AbstractAssertionsAndVariablesStep_1.AbstractAssertionsAndVariablesStep {
    static stepName = 'DatabaseQuery';
    static actionCode = 'database_query';
    static mablScriptStepNames = [DatabaseQueryStep.actionCode];
    static yamlMablScriptNames = [DatabaseQueryStep.stepName];
    constructor(descriptor) {
        super(DatabaseQueryStep.stepName, descriptor, DatabaseQueryStep.actionCode);
        if (!this.isValidDescriptor(this.descriptor)) {
            throw new Error(`${DatabaseQueryStep.stepName}: descriptor.snippet must be defined`);
        }
    }
    isValidDescriptor(value) {
        return value.snippet !== undefined;
    }
    static fromYaml(_stepName, stepArgs) {
        return new DatabaseQueryStep(stepArgs);
    }
    static fromLegacyMablscript(args, actions) {
        if (args.length !== 1) {
            throw new Error(`DatabaseQueryStep fromLegacyMablscript expects 1 argument, got ${args.length}`);
        }
        const step = new DatabaseQueryStep(args[0]);
        step.actions = actions;
        return step;
    }
    stepDescription() {
        return `Database query execution`;
    }
}
exports.DatabaseQueryStep = DatabaseQueryStep;
var DatabaseQueryVariableSource;
(function (DatabaseQueryVariableSource) {
    DatabaseQueryVariableSource["Metadata"] = "metadata";
    DatabaseQueryVariableSource["Result"] = "result";
})(DatabaseQueryVariableSource || (exports.DatabaseQueryVariableSource = DatabaseQueryVariableSource = {}));
function isDatabaseQueryStep(step) {
    return step.getStepName() === DatabaseQueryStep.stepName;
}
