"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StepGroupStep = void 0;
exports.isStepGroupStep = isStepGroupStep;
const MablAction_1 = require("../MablAction");
const MablStepV2_1 = require("../MablStepV2");
class StepGroupStep extends MablStepV2_1.MablStepV2 {
    static stepName = 'StepGroup';
    static actionCode = 'step_group';
    static mablScriptStepNames = [StepGroupStep.actionCode];
    static yamlMablScriptNames = [StepGroupStep.stepName];
    steps;
    intent;
    isMobile;
    interpretSteps;
    constructor(descriptor, interpretSteps) {
        super(StepGroupStep.stepName, descriptor, StepGroupStep.actionCode);
        if (!this.isValidDescriptor(this.descriptor)) {
            throw new Error(`${StepGroupStep.stepName}: descriptor.intent must be defined and descriptor.steps must be an array`);
        }
        this.interpretSteps = interpretSteps;
        this.intent = this.descriptor.intent;
        this.isMobile = this.descriptor.isMobile ?? false;
        this.steps = this.interpretSteps(this.descriptor.steps, this.isMobile);
    }
    isValidDescriptor(value) {
        return value.intent !== undefined && Array.isArray(value.steps);
    }
    getStepName() {
        return StepGroupStep.stepName;
    }
    static fromLegacyMablscript(_args, _actions) {
        throw new Error('Legacy mablscript conversion not supported for StepGroupStep');
    }
    toMablscript() {
        throw new Error('Legacy mablscript generation not supported for StepGroupStep');
    }
    stepDescription() {
        return `Step Group: "${this.intent.description}" (${this.steps.length} steps)`;
    }
    getInputVariables() {
        const inputVariables = this.steps.flatMap((step) => {
            if (typeof step.getInputVariables === 'function') {
                return step.getInputVariables();
            }
            return [];
        });
        return (0, MablAction_1.distinctStrings)(inputVariables);
    }
    getOutputVariables() {
        return this.steps.flatMap((step) => {
            if (typeof step.getOutputVariables === 'function') {
                return step.getOutputVariables();
            }
            return [];
        });
    }
    getSteps() {
        return this.steps;
    }
    setStepSourceIndexInFlow(index) {
        this.stepSourceIndexInFlow = index;
        this.steps.forEach((step) => {
            step.setStepSourceIndexInFlow(index);
        });
    }
}
exports.StepGroupStep = StepGroupStep;
function isStepGroupStep(value) {
    return value?.getStepName?.() === StepGroupStep.stepName;
}
