"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHostRowHardwareInfo = exports.getSimpleHardwareInfo = exports.getHumanizedCpuClockSpeed = exports.getDiskCapacity = exports.getMemoryCapacity = void 0;
const tslib_1 = require("tslib");
const humanize_plus_1 = tslib_1.__importDefault(require("humanize-plus"));
const constants_1 = require("../constants");
const utils_1 = require("../../utils");
const getMemoryCapacity = (inventory) => { var _a; return ((_a = inventory.memory) === null || _a === void 0 ? void 0 : _a.physicalBytes) || 0; };
exports.getMemoryCapacity = getMemoryCapacity;
const getDiskCapacity = (inventory) => {
    var _a;
    return ((_a = inventory.disks) === null || _a === void 0 ? void 0 : _a.filter((disk) => disk.driveType !== constants_1.OpticalDiskDriveType && !disk.holders).reduce((diskSize, disk) => diskSize + (disk.sizeBytes || 0), 0)) || 0;
};
exports.getDiskCapacity = getDiskCapacity;
const getHumanizedCpuClockSpeed = (inventory) => { var _a; return humanize_plus_1.default.formatNumber(((_a = inventory.cpu) === null || _a === void 0 ? void 0 : _a.frequency) || 0); };
exports.getHumanizedCpuClockSpeed = getHumanizedCpuClockSpeed;
const getSimpleHardwareInfo = (inventory) => {
    var _a;
    return ({
        cores: ((_a = inventory.cpu) === null || _a === void 0 ? void 0 : _a.count) || 0,
        memory: (0, exports.getMemoryCapacity)(inventory),
        disks: (0, exports.getDiskCapacity)(inventory),
    });
};
exports.getSimpleHardwareInfo = getSimpleHardwareInfo;
const EMPTY = {
    title: constants_1.DASH,
    sortableValue: 0,
};
const getHostRowHardwareInfo = (inventory) => {
    var _a, _b, _c, _d, _e, _f, _g;
    let cores = EMPTY;
    let memory = EMPTY;
    let disk = EMPTY;
    let cpuSpeed = constants_1.DASH;
    if ((_a = inventory.cpu) === null || _a === void 0 ? void 0 : _a.count) {
        const hyperThreading = ((_c = (_b = inventory.cpu) === null || _b === void 0 ? void 0 : _b.flags) === null || _c === void 0 ? void 0 : _c.includes('ht')) ? ' (hyper-threaded)' : '';
        cpuSpeed = `${(_d = inventory.cpu) === null || _d === void 0 ? void 0 : _d.count} cores${hyperThreading} at ${(0, exports.getHumanizedCpuClockSpeed)(inventory)} MHz`;
        cores = {
            title: (_e = inventory.cpu) === null || _e === void 0 ? void 0 : _e.count.toString(),
            sortableValue: (_f = inventory.cpu) === null || _f === void 0 ? void 0 : _f.count,
        };
    }
    const memCapacity = (0, exports.getMemoryCapacity)(inventory);
    if (memCapacity) {
        memory = {
            title: (0, utils_1.fileSize)(memCapacity, 2, 'iec'),
            sortableValue: memCapacity,
        };
    }
    const disksCapacity = (0, exports.getDiskCapacity)(inventory);
    if (disksCapacity) {
        disk = {
            title: (0, utils_1.fileSize)(disksCapacity, 2, 'si'),
            sortableValue: disksCapacity,
        };
    }
    return {
        serialNumber: ((_g = inventory.systemVendor) === null || _g === void 0 ? void 0 : _g.serialNumber) || constants_1.DASH,
        cores,
        cpuSpeed,
        memory,
        disk,
    };
};
exports.getHostRowHardwareInfo = getHostRowHardwareInfo;
//# sourceMappingURL=hardwareInfo.js.map