"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElseIfConditionStep = void 0;
exports.isElseIfConditionStep = isElseIfConditionStep;
const IfConditionStep_1 = require("./IfConditionStep");
class ElseIfConditionStep extends IfConditionStep_1.IfConditionStep {
    static stepName = 'ElseIf';
    static actionCode = 'conditional_else_if';
    static mablScriptStepNames = [ElseIfConditionStep.actionCode];
    static yamlMablScriptNames = [ElseIfConditionStep.stepName];
    constructor(descriptor, stepActions) {
        super(ElseIfConditionStep.stepName, ElseIfConditionStep.actionCode, descriptor, stepActions);
    }
    getStepName() {
        return ElseIfConditionStep.stepName;
    }
    static fromYaml(_stepName, stepArgs) {
        const actions = IfConditionStep_1.IfConditionStep.getActionsFromYamlForCondition(stepArgs);
        const validatedActions = IfConditionStep_1.IfConditionStep.validateAndParseActions(actions);
        const stepDescriptor = IfConditionStep_1.IfConditionStep.buildDescriptor(validatedActions);
        if (stepArgs.observationScope) {
            stepDescriptor.observationScope =
                stepArgs.observationScope;
        }
        const step = new ElseIfConditionStep(stepDescriptor, validatedActions);
        step.setStepId(stepArgs.id);
        if (stepArgs.annotation) {
            step.setAnnotation(stepArgs.annotation);
        }
        if (stepArgs.description) {
            step.setDescription(stepArgs.description);
        }
        if (stepArgs.disabled) {
            step.setDisabled(stepArgs.disabled);
        }
        return step;
    }
    static fromLegacyMablscript(_args, actions) {
        const validatedActions = IfConditionStep_1.IfConditionStep.validateAndParseActions(actions);
        const stepDescriptor = IfConditionStep_1.IfConditionStep.buildDescriptor(validatedActions);
        const step = new ElseIfConditionStep(stepDescriptor, validatedActions);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        const actions = [
            this.primaryAction,
            this.extractAction,
            this.conditionAction,
        ].filter(Boolean);
        return `conditional_else().${actions.reduce((mablscript, action) => `${mablscript}${action?.toMablscript()}.`, '')}conditional_else_if()`;
    }
}
exports.ElseIfConditionStep = ElseIfConditionStep;
function isElseIfConditionStep(value) {
    return (value?.getStepName &&
        value?.getStepName() === ElseIfConditionStep.yamlMablScriptNames[0]);
}
