"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNetworkInitialValues = void 0;
const tslib_1 = require("tslib");
const is_cidr_1 = tslib_1.__importDefault(require("is-cidr"));
const utils_1 = require("../../../common/components/clusterConfiguration/utils");
const common_1 = require("../../../common");
const getNetworkInitialValues = (cluster, defaultNetworkSettings) => {
    var _a, _b, _c;
    const managedNetworkingType = cluster.userManagedNetworking ? 'userManaged' : 'clusterManaged';
    const isDualStackCluster = (0, utils_1.isDualStack)(cluster);
    const primaryMachineCidr = (_b = (_a = cluster.machineNetworks) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.cidr;
    const isSingleStackIPv6 = !isDualStackCluster && primaryMachineCidr && is_cidr_1.default.v6(primaryMachineCidr);
    let clusterNetworks = cluster.clusterNetworks;
    if (!((_c = cluster.clusterNetworks) === null || _c === void 0 ? void 0 : _c.length)) {
        if (isDualStackCluster) {
            clusterNetworks = defaultNetworkSettings.clusterNetworksDualstack;
        }
        else if (isSingleStackIPv6) {
            clusterNetworks = defaultNetworkSettings.clusterNetworksIpv6;
        }
        else {
            clusterNetworks = defaultNetworkSettings.clusterNetworksIpv4;
        }
    }
    let serviceNetworks = cluster.serviceNetworks;
    if (!(serviceNetworks === null || serviceNetworks === void 0 ? void 0 : serviceNetworks.length)) {
        if (isDualStackCluster) {
            serviceNetworks = defaultNetworkSettings.serviceNetworksDualstack;
        }
        else if (isSingleStackIPv6) {
            serviceNetworks = defaultNetworkSettings.serviceNetworksIpv6;
        }
        else {
            serviceNetworks = defaultNetworkSettings.serviceNetworksIpv4;
        }
    }
    const machineNetworks = cluster.machineNetworks || [];
    return {
        clusterNetworks,
        serviceNetworks,
        machineNetworks,
        apiVips: cluster.apiVips,
        ingressVips: cluster.ingressVips,
        sshPublicKey: cluster.sshPublicKey || '',
        vipDhcpAllocation: cluster.vipDhcpAllocation,
        managedNetworkingType,
        networkType: cluster.networkType || common_1.NETWORK_TYPE_OVN,
        stackType: isDualStackCluster ? common_1.DUAL_STACK : common_1.SINGLE_STACK,
    };
};
exports.getNetworkInitialValues = getNetworkInitialValues;
//# sourceMappingURL=networkConfigurationValidation.js.map