"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readApplicationEnterTextMode = readApplicationEnterTextMode;
exports.loadApplicationConfig = loadApplicationConfig;
const mablApi_1 = require("../mablApi");
const loggingProvider_1 = require("../providers/logging/loggingProvider");
function readApplicationEnterTextMode(application) {
    const mode = application.enter_text_mode;
    return mode === mablApi_1.EnterTextModeEnum.Fill || mode === mablApi_1.EnterTextModeEnum.Press
        ? mode
        : undefined;
}
const EMPTY_CONFIG = {
    customTestIdAttributes: [],
    enterTextMode: undefined,
};
async function loadApplicationConfig(apiClient, applicationId) {
    if (!applicationId) {
        return EMPTY_CONFIG;
    }
    try {
        const application = await apiClient.getApplication(applicationId);
        return {
            customTestIdAttributes: application.custom_test_id_attributes ?? [],
            enterTextMode: readApplicationEnterTextMode(application),
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        loggingProvider_1.logger.warn(`Could not load application config for ${applicationId}: ${message}`);
        return EMPTY_CONFIG;
    }
}
