"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLimitedFeatureSupportLevels = void 0;
const utils_1 = require("../../utils");
const getLimitedFeatureSupportLevels = (cluster, featureSupportLevelData, t) => {
    if (!cluster.openshiftVersion) {
        throw t
            ? t("ai:cluster doesn't contain the openshift_version field")
            : "cluster doesn't contain the openshift_version field";
    }
    if (!cluster.featureUsage) {
        throw t
            ? t("ai:cluster doesn't contain the feature_usage field")
            : "ai:cluster doesn't contain the feature_usage field";
    }
    const ret = {};
    const featureUsage = (0, utils_1.stringToJSON)(cluster.featureUsage);
    if (featureUsage === undefined) {
        throw t
            ? t('ai:Error parsing cluster feature_usage field')
            : 'Error parsing cluster feature_usage field';
    }
    const usedFeatureIds = Object.values(featureUsage).map((item) => item.id);
    const versionSupportLevels = featureSupportLevelData.getFeatureSupportLevels();
    if (!versionSupportLevels) {
        throw t
            ? t('ai:No support level data for version {{openshiftVersion}}', {
                openshiftVersion: cluster.openshiftVersion,
            })
            : `No support level data for version ${cluster.openshiftVersion}`;
    }
    for (const featureId of usedFeatureIds) {
        if (featureId in versionSupportLevels) {
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            const supportLevel = versionSupportLevels[featureId];
            if (supportLevel === 'supported') {
                continue;
            }
            ret[featureId] = supportLevel;
        }
    }
    return ret;
};
exports.getLimitedFeatureSupportLevels = getLimitedFeatureSupportLevels;
//# sourceMappingURL=utils.js.map