"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hostsNetworkConfigurationDisabledReason = exports.isFeatureSupportedAndAvailable = exports.getNewFeatureDisabledReason = exports.clusterExistsReason = void 0;
const common_1 = require("../../../common");
const constants_1 = require("../clusterConfiguration/platformIntegration/constants");
const operatorSpecs_1 = require("../../../common/components/operators/operatorSpecs");
exports.clusterExistsReason = 'This option is not editable after the draft cluster is created';
const getSNODisabledReason = (cluster, isSupported) => {
    if (cluster) {
        return exports.clusterExistsReason;
    }
    if (!isSupported) {
        return 'Single-Node OpenShift is not supported in this OpenShift version';
    }
    return '';
};
const getArmDisabledReason = (cluster) => {
    if (cluster) {
        return exports.clusterExistsReason;
    }
    else
        return 'arm64 is not supported in this OpenShift version';
};
const getOdfDisabledReason = (cluster, activeFeatureConfiguration, isSupported) => {
    if (!cluster) {
        return undefined;
    }
    const operatorTitle = (0, operatorSpecs_1.getOperatorTitleByFeatureId)('ODF') || '';
    const isArm = (activeFeatureConfiguration === null || activeFeatureConfiguration === void 0 ? void 0 : activeFeatureConfiguration.underlyingCpuArchitecture) === common_1.CpuArchitecture.ARM;
    if (isArm && (0, common_1.isSNO)(cluster)) {
        return `${operatorTitle} is not available when using Single Node OpenShift or ARM CPU architecture.`;
    }
    if (isArm) {
        return `${operatorTitle} is not available when ARM CPU architecture is selected.`;
    }
    if ((0, common_1.isSNO)(cluster)) {
        return `${operatorTitle} is not available when deploying a Single Node OpenShift.`;
    }
    if (!isSupported) {
        return `The installer cannot currently enable ${operatorTitle} with the selected OpenShift version, but it can be enabled later through the OpenShift Console once the installation is complete.`;
    }
    return undefined;
};
const getCnvDisabledReason = (activeFeatureConfiguration, isSupported, platformType) => {
    if (!activeFeatureConfiguration) {
        return undefined;
    }
    const operatorTitle = (0, operatorSpecs_1.getOperatorTitleByFeatureId)('CNV') || '';
    if (platformType === 'nutanix') {
        return `${operatorTitle} is not available when Nutanix platform type is selected.`;
    }
    if (!isSupported) {
        const cpuArchitectureLabel = common_1.architectureData[activeFeatureConfiguration.underlyingCpuArchitecture].label;
        return `${operatorTitle} is not available when ${cpuArchitectureLabel
            ? cpuArchitectureLabel
            : activeFeatureConfiguration.underlyingCpuArchitecture} CPU architecture is selected.`;
    }
    else {
        return undefined;
    }
};
const getLvmDisabledReason = (activeFeatureConfiguration, isSupported, platformType) => {
    if (!activeFeatureConfiguration) {
        return undefined;
    }
    const operatorTitle = (0, operatorSpecs_1.getOperatorTitleByFeatureId)('LVM') || '';
    if (platformType === 'nutanix') {
        return `${operatorTitle} is not supported when Nutanix platform type is selected.`;
    }
    if (!isSupported) {
        return `${operatorTitle} is not supported in this OpenShift version.`;
    }
    return undefined;
};
const getOscDisabledReason = (cluster, activeFeatureConfiguration, isSupported) => {
    if (!cluster) {
        return undefined;
    }
    const operatorTitle = (0, operatorSpecs_1.getOperatorTitleByFeatureId)('OSC') || '';
    if (!isSupported) {
        return `${operatorTitle} is not supported in this OpenShift version.`;
    }
    return undefined;
};
const getNetworkTypeSelectionDisabledReason = (cluster) => {
    if (!cluster) {
        return undefined;
    }
    if ((0, common_1.isSNO)(cluster)) {
        return 'Network management selection is not supported for Single-Node OpenShift';
    }
    return undefined;
};
const getOciDisabledReason = (cpuArchitecture, isSupported) => {
    if (!isSupported) {
        if (cpuArchitecture === common_1.CpuArchitecture.s390x || cpuArchitecture === common_1.CpuArchitecture.ppc64le) {
            return `Integration with Oracle is not available with the selected CPU architecture.`;
        }
        else {
            return 'Integration with Oracle is available for OpenShift 4.14 and later versions.';
        }
    }
};
const getSDNDisabledReason = (cluster, isSupported) => {
    if (cluster && (0, common_1.isSNO)(cluster)) {
        return 'SDN is not supported for single-node clusters.';
    }
    if (cluster && (0, common_1.isDualStack)(cluster)) {
        return 'SDN is not supported for dual-stack clusters.';
    }
    if (!isSupported) {
        return 'SDN is not supported for the selected configuration.';
    }
    return undefined;
};
const getNewFeatureDisabledReason = (featureId, cluster, activeFeatureConfiguration, isSupported, cpuArchitecture, platformType) => {
    var _a, _b;
    switch (featureId) {
        case 'SNO': {
            return getSNODisabledReason(cluster, isSupported);
        }
        case 'ARM64_ARCHITECTURE': {
            return getArmDisabledReason(cluster);
        }
        case 'CNV': {
            return getCnvDisabledReason(activeFeatureConfiguration, isSupported, platformType !== null && platformType !== void 0 ? platformType : (_a = cluster === null || cluster === void 0 ? void 0 : cluster.platform) === null || _a === void 0 ? void 0 : _a.type);
        }
        case 'LVM': {
            return getLvmDisabledReason(activeFeatureConfiguration, isSupported, platformType !== null && platformType !== void 0 ? platformType : (_b = cluster === null || cluster === void 0 ? void 0 : cluster.platform) === null || _b === void 0 ? void 0 : _b.type);
        }
        case 'ODF': {
            return getOdfDisabledReason(cluster, activeFeatureConfiguration, isSupported);
        }
        case 'OPENSHIFT_AI': {
            return getOpenShiftAIDisabledReason(cluster, activeFeatureConfiguration, isSupported);
        }
        case 'OSC': {
            return getOscDisabledReason(cluster, activeFeatureConfiguration, isSupported);
        }
        case 'SDN_NETWORK_TYPE': {
            return getSDNDisabledReason(cluster, isSupported);
        }
        case 'NETWORK_TYPE_SELECTION': {
            return getNetworkTypeSelectionDisabledReason(cluster);
        }
        case 'CLUSTER_MANAGED_NETWORKING': {
            return `Cluster-managed networking is not supported when using ${platformType ? constants_1.ExternalPlatformLabels[platformType] : ''}`;
        }
        case 'EXTERNAL_PLATFORM_OCI': {
            return getOciDisabledReason(cpuArchitecture, isSupported);
        }
        case 'MCE': {
            if (platformType === 'nutanix') {
                return 'Multicluster engine is not supported with Nutanix platform type.';
            }
            if (!isSupported) {
                return 'Multicluster engine is not supported in this OpenShift version.';
            }
        }
        case 'NUTANIX_INTEGRATION': {
            if (!isSupported) {
                return `Integration with Nutanix is not available with the selected CPU architecture.`;
            }
        }
        case 'VSPHERE_INTEGRATION': {
            if (!isSupported) {
                return `Integration with vSphere is not available with the selected CPU architecture.`;
            }
        }
        case 'USER_MANAGED_NETWORKING': {
            if (!isSupported) {
                return `User-Managed networking is not supported when using ${platformType ? constants_1.ExternalPlatformLabels[platformType] : ''}`;
            }
        }
        case 'MTV': {
            if (!isSupported) {
                return 'Migration Toolkit for Virtualization is not supported in this OpenShift version';
            }
        }
        case 'AUTHORINO': {
            if (!isSupported) {
                return `Authorino is not available with the selected CPU architecture.`;
            }
        }
        case 'LSO': {
            if (!isSupported) {
                return `Lso is not available with the selected CPU architecture.`;
            }
        }
        case 'NMSTATE': {
            if (!isSupported) {
                return `Nmstate is not available with the selected CPU architecture.`;
            }
        }
        case 'NODE_FEATURE_DISCOVERY': {
            if (!isSupported) {
                return `Node Feature Discovery is not available with the selected CPU architecture.`;
            }
        }
        case 'NVIDIA_GPU': {
            if (!isSupported) {
                return `NVIDIA GPU is not available with the selected CPU architecture.`;
            }
        }
        case 'PIPELINES': {
            if (!isSupported) {
                return `Pipelines is not available with the selected CPU architecture.`;
            }
        }
        case 'SERVERLESS': {
            if (!isSupported) {
                return `Serverless is not available with the selected CPU architecture.`;
            }
        }
        case 'SERVICEMESH': {
            if (!isSupported) {
                return `Service mesh is not available with the selected CPU architecture.`;
            }
        }
        case 'AMD_GPU': {
            if (!isSupported) {
                return `AMD GPU is not available with the selected CPU architecture.`;
            }
        }
        default: {
            return undefined;
        }
    }
};
exports.getNewFeatureDisabledReason = getNewFeatureDisabledReason;
const isFeatureSupportedAndAvailable = (supportLevel) => {
    return supportLevel !== 'unsupported' && supportLevel !== 'unavailable';
};
exports.isFeatureSupportedAndAvailable = isFeatureSupportedAndAvailable;
exports.hostsNetworkConfigurationDisabledReason = "DHCP only is the supported hosts' network configuration when external partner integrations is selected";
const getOpenShiftAIDisabledReason = (cluster, activeFeatureConfiguration, isSupported) => {
    if (!cluster) {
        return undefined;
    }
    const operatorTitle = (0, operatorSpecs_1.getOperatorTitleByFeatureId)('OPENSHIFT_AI') || '';
    const isArm = (activeFeatureConfiguration === null || activeFeatureConfiguration === void 0 ? void 0 : activeFeatureConfiguration.underlyingCpuArchitecture) === common_1.CpuArchitecture.ARM;
    if (isArm) {
        return `${operatorTitle} is not available when ARM CPU architecture is selected.`;
    }
    if (!isSupported) {
        return `The installer cannot currently enable ${operatorTitle} with the selected OpenShift version, but it can be enabled later through the OpenShift Console once the installation is complete.`;
    }
    return undefined;
};
//# sourceMappingURL=featureStateUtils.js.map