"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizeError = exports.formatEnvData = exports.formatFlagsData = exports.getAllFeatureFlags = void 0;
const featureFlags_1 = require("../featureFlags");
const axios_1 = __importDefault(require("axios"));
const getAllFeatureFlags = (appLanguage, localOverrides) => {
    const res = {};
    Object.keys(featureFlags_1.DEFAULT_FEATURES).forEach(k => {
        const key = k;
        const value = (0, featureFlags_1.getFeature)({ key, appLanguage, localOverrides });
        if (value !== null)
            res[key] = value;
    });
    return res;
};
exports.getAllFeatureFlags = getAllFeatureFlags;
const formatFlagsData = (data) => {
    let allureData = "";
    for (const [key, value] of Object.entries(data)) {
        if (!value)
            continue;
        if (!value.enabled)
            continue;
        allureData += `FF.${key} = ${value.enabled}\n`;
        const entries = {
            desktop_version: value.desktop_version,
            mobile_version: value.mobile_version,
            enabledOverriddenForCurrentVersion: value.enabledOverriddenForCurrentVersion,
            languages_whitelisted: value.languages_whitelisted?.join(", "),
            languages_blacklisted: value.languages_blacklisted?.join(", "),
            enabledOverriddenForCurrentLanguage: value.enabledOverriddenForCurrentLanguage,
            overridesRemote: value.overridesRemote,
            overriddenByEnv: value.overriddenByEnv,
            params: value.params ? JSON.stringify(value.params) : undefined,
        };
        for (const [field, fieldValue] of Object.entries(entries)) {
            if (fieldValue !== undefined) {
                allureData += `FF.${key}.${field} = ${fieldValue
                    .toString()
                    .replace(/^\{|\}$/g, "")
                    .replace(/"/g, " ")}\n`;
            }
        }
    }
    return allureData;
};
exports.formatFlagsData = formatFlagsData;
const formatEnvData = (data) => {
    let allureData = "";
    for (const [key, value] of Object.entries(data)) {
        allureData += `ENV.${key} = ${value}\n`;
    }
    return allureData;
};
exports.formatEnvData = formatEnvData;
const sanitizeError = (error) => {
    if (!axios_1.default.isAxiosError(error)) {
        return error instanceof Error ? error : new Error(String(error ?? "Unknown error"));
    }
    const err = error;
    const sanitized = new Error(err.message || "Axios request failed");
    Object.assign(sanitized, {
        name: err.name,
        code: err.code,
        url: err.config?.url,
        method: err.config?.method,
        status: err.response?.status,
    });
    return sanitized;
};
exports.sanitizeError = sanitizeError;
//# sourceMappingURL=index.js.map