"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractAssertionsAndVariablesStep = void 0;
const mablscriptFind_1 = require("../mablscriptFind");
const MablAction_1 = require("../MablAction");
const MablStepV2_1 = require("../MablStepV2");
const ConditionDescriptor_1 = require("../types/ConditionDescriptor");
const AssertStep_1 = require("./AssertStep");
class AbstractAssertionsAndVariablesStep extends MablStepV2_1.MablStepV2 {
    constructor(name, descriptor, actionCode) {
        super(name, descriptor, actionCode);
    }
    getStepName() {
        return this.name;
    }
    stepDescription() {
        return `Execute ${this.getStepName()}`;
    }
    toStepDescriptor() {
        const formatted = JSON.parse(JSON.stringify(this.descriptor));
        formatted.actionCode = this.actionCode;
        formatted.assertions?.forEach((assertion) => {
            if (!(0, ConditionDescriptor_1.isComparisonType)(assertion.assertion)) {
                throw new Error(`Invalid comparison type: ${assertion.assertion}`);
            }
        });
        return formatted;
    }
    toMablscript() {
        const { actionCode, description, ...params } = this.toStepDescriptor();
        return `${this.getActionCode()}(${(0, mablscriptFind_1.buildStepArgumentString)({
            params,
            legacy: true,
        })})`;
    }
    getInputVariables() {
        return MablAction_1.MablAction.findUniqueVariableReferencesInValue(this.descriptor);
    }
    getOutputVariables() {
        return this.descriptor.variables?.map((variable) => variable.name) ?? [];
    }
    canContinueOnFailure() {
        return ((this.descriptor.options?.onFailure ?? AssertStep_1.OnFailure.FailImmediately) !==
            AssertStep_1.OnFailure.FailImmediately);
    }
    canFailAtEnd() {
        return this.descriptor.options?.onFailure === AssertStep_1.OnFailure.FailTestAtEnd;
    }
}
exports.AbstractAssertionsAndVariablesStep = AbstractAssertionsAndVariablesStep;
