"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.numberOfEnabledOperators = exports.isClusterPlatformTypeVM = exports.selectSchedulableMasters = exports.selectMastersMustRunWorkloads = exports.selectIpv6HostPrefix = exports.selectIpv4HostPrefix = exports.selectIpv6Cidr = exports.selectIpv4Cidr = exports.selectClusterValidationsInfo = exports.isSNO = exports.isCompact = exports.hasEnabledOperators = exports.selectOlmOperators = exports.selectMonitoredOperators = exports.selectIngressVip = exports.selectApiVip = exports.selectServiceNetworkCIDR = exports.selectClusterNetworkHostPrefix = exports.selectClusterNetworkCIDR = exports.selectMachineNetworkCIDR = void 0;
const tslib_1 = require("tslib");
const head_js_1 = tslib_1.__importDefault(require("lodash-es/head.js"));
const types_1 = require("../types");
const utils_1 = require("../utils");
const selectMachineNetworkCIDR = ({ machineNetworks, machineNetworkCidr, }) => { var _a, _b; return (_b = (_a = (0, head_js_1.default)(machineNetworks)) === null || _a === void 0 ? void 0 : _a.cidr) !== null && _b !== void 0 ? _b : machineNetworkCidr; };
exports.selectMachineNetworkCIDR = selectMachineNetworkCIDR;
const selectClusterNetworkCIDR = ({ clusterNetworks, clusterNetworkCidr, }) => { var _a, _b; return (_b = (_a = (0, head_js_1.default)(clusterNetworks)) === null || _a === void 0 ? void 0 : _a.cidr) !== null && _b !== void 0 ? _b : clusterNetworkCidr; };
exports.selectClusterNetworkCIDR = selectClusterNetworkCIDR;
const selectClusterNetworkHostPrefix = ({ clusterNetworks, clusterNetworkHostPrefix, }) => { var _a, _b; return (_b = (_a = (0, head_js_1.default)(clusterNetworks)) === null || _a === void 0 ? void 0 : _a.hostPrefix) !== null && _b !== void 0 ? _b : clusterNetworkHostPrefix; };
exports.selectClusterNetworkHostPrefix = selectClusterNetworkHostPrefix;
const selectServiceNetworkCIDR = ({ serviceNetworks, serviceNetworkCidr, }) => { var _a, _b; return (_b = (_a = (0, head_js_1.default)(serviceNetworks)) === null || _a === void 0 ? void 0 : _a.cidr) !== null && _b !== void 0 ? _b : serviceNetworkCidr; };
exports.selectServiceNetworkCIDR = selectServiceNetworkCIDR;
const selectApiVip = ({ apiVips }) => { var _a; return ((_a = (0, head_js_1.default)(apiVips)) === null || _a === void 0 ? void 0 : _a.ip) || ''; };
exports.selectApiVip = selectApiVip;
const selectIngressVip = ({ ingressVips }) => { var _a; return ((_a = (0, head_js_1.default)(ingressVips)) === null || _a === void 0 ? void 0 : _a.ip) || ''; };
exports.selectIngressVip = selectIngressVip;
const selectMonitoredOperators = (monitoredOperators) => {
    // monitoredOperators can sometimes be either undefined or also null, we must use the fallback
    return monitoredOperators || [];
};
exports.selectMonitoredOperators = selectMonitoredOperators;
const selectOlmOperators = (cluster) => {
    return (0, exports.selectMonitoredOperators)(cluster === null || cluster === void 0 ? void 0 : cluster.monitoredOperators).filter((operator) => operator.operatorType === 'olm');
};
exports.selectOlmOperators = selectOlmOperators;
const hasEnabledOperators = (monitoredOperators, searchOperator) => {
    return (0, exports.selectMonitoredOperators)(monitoredOperators).some((operator) => operator.name && operator.name === searchOperator);
};
exports.hasEnabledOperators = hasEnabledOperators;
const isCompact = (cluster) => {
    return !cluster.hosts || cluster.hosts.length <= 3;
};
exports.isCompact = isCompact;
const isSNO = ({ controlPlaneCount }) => controlPlaneCount === 1;
exports.isSNO = isSNO;
const selectClusterValidationsInfo = ({ validationsInfo, }) => {
    return (0, utils_1.stringToJSON)(validationsInfo);
};
exports.selectClusterValidationsInfo = selectClusterValidationsInfo;
const selectIpv4Cidr = ({ machineNetworks, serviceNetworks, clusterNetworks, }, key) => {
    var _a, _b, _c;
    switch (key) {
        case 'machineNetworks':
            return (_a = (0, head_js_1.default)(machineNetworks)) === null || _a === void 0 ? void 0 : _a.cidr;
        case 'clusterNetworks':
            return (_b = (0, head_js_1.default)(clusterNetworks)) === null || _b === void 0 ? void 0 : _b.cidr;
        case 'serviceNetworks':
            return (_c = (0, head_js_1.default)(serviceNetworks)) === null || _c === void 0 ? void 0 : _c.cidr;
    }
};
exports.selectIpv4Cidr = selectIpv4Cidr;
const selectIpv6Cidr = ({ machineNetworks, serviceNetworks, clusterNetworks, }, key) => {
    switch (key) {
        case 'machineNetworks':
            return machineNetworks && machineNetworks[1].cidr;
        case 'clusterNetworks':
            return clusterNetworks && clusterNetworks[1].cidr;
        case 'serviceNetworks':
            return serviceNetworks && serviceNetworks[1].cidr;
    }
};
exports.selectIpv6Cidr = selectIpv6Cidr;
const selectIpv4HostPrefix = ({ clusterNetworks }) => { var _a; return (_a = (0, head_js_1.default)(clusterNetworks)) === null || _a === void 0 ? void 0 : _a.hostPrefix; };
exports.selectIpv4HostPrefix = selectIpv4HostPrefix;
const selectIpv6HostPrefix = ({ clusterNetworks }) => clusterNetworks && clusterNetworks[1].hostPrefix;
exports.selectIpv6HostPrefix = selectIpv6HostPrefix;
const selectMastersMustRunWorkloads = (cluster) => !!cluster.schedulableMastersForcedTrue;
exports.selectMastersMustRunWorkloads = selectMastersMustRunWorkloads;
const selectSchedulableMasters = (cluster) => {
    if ((0, exports.selectMastersMustRunWorkloads)(cluster)) {
        return true;
    }
    return cluster.schedulableMasters || false;
};
exports.selectSchedulableMasters = selectSchedulableMasters;
const isClusterPlatformTypeVM = ({ platform }) => { var _a; 
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return types_1.SupportedPlatformIntegrations.includes((_a = platform === null || platform === void 0 ? void 0 : platform.type) !== null && _a !== void 0 ? _a : 'none'); };
exports.isClusterPlatformTypeVM = isClusterPlatformTypeVM;
const numberOfEnabledOperators = (monitoredOperators) => {
    return monitoredOperators
        ? (0, exports.selectMonitoredOperators)(monitoredOperators.filter((operator) => operator.operatorType === 'olm')).length
        : 0;
};
exports.numberOfEnabledOperators = numberOfEnabledOperators;
//# sourceMappingURL=clusterSelectors.js.map