"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaitStep = void 0;
const MablStepV2_1 = require("../MablStepV2");
class WaitStep extends MablStepV2_1.MablStepV2 {
    static stepName = 'Wait';
    static actionCode = 'wait';
    static mablScriptStepNames = [WaitStep.actionCode];
    static yamlMablScriptNames = [WaitStep.stepName];
    milliseconds;
    constructor(descriptor) {
        super(WaitStep.stepName, descriptor, WaitStep.actionCode);
        this.milliseconds = descriptor.milliseconds;
    }
    getStepName() {
        return WaitStep.stepName;
    }
    static fromYaml(_stepName, stepArgs) {
        const stepDescriptor = stepArgs;
        WaitStep.validateWait(stepDescriptor.milliseconds);
        return new WaitStep(stepDescriptor);
    }
    static fromLegacyMablscript(args, actions) {
        const stepDescriptor = {
            milliseconds: WaitStep.validateWait(args[0]),
        };
        const step = new WaitStep(stepDescriptor);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        return `wait(${this.milliseconds})`;
    }
    stepDescription() {
        return `Wait for ${this.milliseconds / 1000} seconds`;
    }
    static validateWait(wait) {
        if (typeof wait !== 'number') {
            throw new Error(`Invalid wait argument [${wait}]`);
        }
        return wait;
    }
    static create(descriptor) {
        descriptor.id = descriptor.id ?? MablStepV2_1.MablStepV2.generateStepId();
        return new WaitStep(descriptor);
    }
}
exports.WaitStep = WaitStep;
