"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHostNetworks = void 0;
const getHostNetworks = (agents, agentClusterInstall) => {
    var _a;
    if (!(agents === null || agents === void 0 ? void 0 : agents.length) || !((_a = agentClusterInstall === null || agentClusterInstall === void 0 ? void 0 : agentClusterInstall.status) === null || _a === void 0 ? void 0 : _a.connectivityMajorityGroups)) {
        return [];
    }
    const connectivityMajorityGroups = JSON.parse(agentClusterInstall.status.connectivityMajorityGroups);
    const majorityGroups = connectivityMajorityGroups.majority_groups || {};
    return Object.keys(majorityGroups)
        .filter((k) => !['IPv4', 'IPv6'].includes(k))
        .map((cidr) => {
        const hostIds = [];
        majorityGroups[cidr].forEach((hostName) => {
            var _a;
            const agent = agents.find((agent) => { var _a; return ((_a = agent.metadata) === null || _a === void 0 ? void 0 : _a.name) === hostName; });
            if (!((_a = agent === null || agent === void 0 ? void 0 : agent.metadata) === null || _a === void 0 ? void 0 : _a.uid)) {
                // console.warn(`Can not find agent of ${hostName} name.`);
            }
            else {
                hostIds.push(agent.metadata.uid);
            }
        });
        return {
            cidr,
            hostIds,
        };
    });
};
exports.getHostNetworks = getHostNetworks;
//# sourceMappingURL=network.js.map