"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnterAuthCodeStep = void 0;
const FindAction_1 = require("../actions/FindAction");
const mablscriptFind_1 = require("../mablscriptFind");
const ActionsUtils_1 = require("./ActionsUtils");
const MablStepWithFindAction_1 = require("../MablStepWithFindAction");
class EnterAuthCodeStep extends MablStepWithFindAction_1.MablStepWithFindAction {
    static stepName = 'EnterAuthCode';
    static actionCode = 'enter_auth_code';
    static mablScriptStepNames = [EnterAuthCodeStep.actionCode];
    static yamlMablScriptNames = [EnterAuthCodeStep.stepName];
    constructor(descriptor, findAction) {
        super(EnterAuthCodeStep.stepName, descriptor, EnterAuthCodeStep.actionCode, findAction);
    }
    getStepName() {
        return EnterAuthCodeStep.stepName;
    }
    static fromYaml(_stepName, stepArgs) {
        const findAction = FindAction_1.FindAction.findActionFromStepArgs(stepArgs);
        const stepDescriptor = buildStepDescriptor(findAction);
        const step = new EnterAuthCodeStep(stepDescriptor, findAction);
        step.setStepId(stepArgs.id);
        return step;
    }
    static fromLegacyMablscript(_args, actions) {
        const findAction = ActionsUtils_1.ActionsUtils.validateSingleFindAction(actions);
        const stepDescriptor = buildStepDescriptor(findAction);
        const step = new EnterAuthCodeStep(stepDescriptor, findAction);
        step.actions = actions;
        return step;
    }
    toMablscript() {
        return `${this.findAction.toMablscript()}.enter_auth_code()`;
    }
    getInputVariables() {
        return this.findAction.getInputVariables();
    }
    stepDescription() {
        const elementDescription = this.humanizeFind();
        return `Enter authentication code into ${elementDescription}`;
    }
}
exports.EnterAuthCodeStep = EnterAuthCodeStep;
function buildStepDescriptor(findAction) {
    const find = findAction.toDescriptor();
    switch (find.findType) {
        case mablscriptFind_1.FindType.FIND_FIRST:
        case mablscriptFind_1.FindType.FIND_LAST:
        case mablscriptFind_1.FindType.FIND_ANY:
        case mablscriptFind_1.FindType.FIND_ONE:
            return {
                find,
                actionCode: EnterAuthCodeStep.actionCode,
            };
        default:
            throw new Error(`Error generating step descriptor for EnterAuthCode: Unexpected find type ${find.findType}`);
    }
}
