"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaitUntilStep = void 0;
const mablscriptFind_1 = require("../mablscriptFind");
const MablStepWithFindAction_1 = require("../MablStepWithFindAction");
const ActionsUtils_1 = require("./ActionsUtils");
class WaitUntilStep extends MablStepWithFindAction_1.MablStepWithFindAction {
    static stepName = 'WaitUntil';
    static actionCode = 'wait_until';
    static mablScriptStepNames = [];
    static yamlMablScriptNames = [WaitUntilStep.stepName];
    constructor(descriptor, findAction) {
        super(WaitUntilStep.stepName, descriptor, WaitUntilStep.actionCode, findAction);
    }
    getStepName() {
        return WaitUntilStep.stepName;
    }
    static fromYaml(_stepName, _stepArgs) {
        throw new Error('YAML support for WaitUntilStep is not yet implemented');
    }
    static fromLegacyMablscript(_args, actions) {
        const findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(actions);
        const stepDescriptor = buildStepDescriptor(findAction);
        const step = new WaitUntilStep(stepDescriptor, findAction);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        return `${this.findAction.toMablscript()}.evaluate_presence("present").assert()`;
    }
    getInputVariables() {
        return this.findAction.getInputVariables();
    }
    stepDescription() {
        const elementDescription = this.humanizeFind();
        return `Wait until ${elementDescription} is present`;
    }
}
exports.WaitUntilStep = WaitUntilStep;
function buildStepDescriptor(findAction) {
    const find = findAction.toDescriptor();
    switch (find.findType) {
        case mablscriptFind_1.FindType.FIND_ONE:
            return {
                find,
                actionCode: WaitUntilStep.actionCode,
            };
        default:
            throw new Error(`Error generating step descriptor for ${WaitUntilStep.stepName}: Unexpected find type ${find.findType} is not supported`);
    }
}
