"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HM_Analytics = void 0;
var os_1 = __importDefault(require("os"));
var uuid_1 = require("uuid");
var axios_1 = __importDefault(require("axios"));
var index_1 = require("./index");
var _a = index_1.config.getLocalConfig(), ANALYTICS_HOST = _a.ANALYTICS_HOST, analyticsKey = _a.analyticsKey;
var getAnalyticsID = function () {
    var _a;
    var _b = index_1.instanceStorage.getStorage(), _c = analyticsKey.id, _d = _b[_c], analyticsId = _d === void 0 ? '' : _d;
    if (!analyticsId) {
        var newAnalyticsId = (0, uuid_1.v4)();
        index_1.globalStorage.set((_a = {},
            _a[analyticsKey.id] = newAnalyticsId,
            _a));
        return newAnalyticsId;
    }
    return analyticsId;
};
var analytics_app_id = 'eb38cc404a5211d59d8b4653cd00c51c';
var HM_Analytics = function (event_id, options) {
    var eventPackage = {
        ltp: 'devops',
        c: {
            uid: getAnalyticsID(),
        },
        e: [
            {
                ei: event_id,
                ep: Object.assign({
                    platform: os_1.default.platform(),
                    release: os_1.default.release(),
                    arch: os_1.default.arch(),
                    node: process.version,
                }, options),
                et: new Date().getTime(),
                etp: 'cnt',
            },
        ],
    };
    var eventPackageStr = Buffer.from(JSON.stringify(eventPackage)).toString('base64');
    axios_1.default
        .post("".concat(ANALYTICS_HOST, "/api/v5/server/collect"), eventPackageStr, {
        headers: {
            appid: analytics_app_id,
            'content-type': 'text/plain',
        },
        timeout: 300,
    })
        .catch(function (_error) { });
};
exports.HM_Analytics = HM_Analytics;
