"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.humanizeExecuteStepGroupStep = humanizeExecuteStepGroupStep;
exports.executeStepGroupStepToAIString = executeStepGroupStepToAIString;
const BaseStep_1 = __importDefault(require("../canonical/BaseStep"));
const mablscript_step_types_1 = require("../../mablscript-step-types");
const StepGroupStep_1 = require("@mablhq/test-model/steps/StepGroupStep");
const importer_1 = require("@mablhq/test-model/importer");
const yaml_utils_1 = require("../yaml-utils");
class ExecuteStepGroupStep extends BaseStep_1.default {
    static getStepType() {
        return mablscript_step_types_1.StepType.EXECUTE_STEP_GROUP;
    }
    constructor(stepsInGroup, description) {
        super(ExecuteStepGroupStep.getStepType());
        this.stepsInGroup = stepsInGroup;
        this.description = description;
        this.collapsed = false;
        if (this.options) {
            this.options.editable = true;
        }
        else {
            this.options = { editable: true };
        }
    }
    generateMablStep() {
        const nestedSteps = this.stepsInGroup.map((step) => step.generateMablStep().getFormattedStep());
        const stepGroupStep = new StepGroupStep_1.StepGroupStep({
            steps: nestedSteps,
            intent: { description: this.description ?? 'Unnamed Step Group' },
            description: this.description,
            actionCode: StepGroupStep_1.StepGroupStep.actionCode,
        }, importer_1.interpretStepsFromObjects);
        stepGroupStep.setDisabled(this.disabled);
        if (this.id) {
            stepGroupStep.setStepId(this.id);
        }
        return stepGroupStep;
    }
    inputVariables() {
        const variables = [];
        this.stepsInGroup.forEach((step) => {
            const stepVars = step.inputVariables?.();
            if (stepVars) {
                variables.push(...stepVars);
            }
        });
        return [...new Set(variables)];
    }
    willGenerateMablscript() {
        return false;
    }
}
exports.default = ExecuteStepGroupStep;
function humanizeExecuteStepGroupStep(step) {
    if (!step.description) {
        return 'Start group: Unnamed Step Group';
    }
    return `Start group: ${step.description}`;
}
function executeStepGroupStepToAIString(step) {
    return (0, yaml_utils_1.toYaml)({
        stepType: step.stepType,
        description: step.description || 'Unnamed Step Group',
        step_count: step.stepsInGroup.length,
    });
}
