"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUserAgent = getUserAgent;
exports.addFeatureFlagsToUserAgent = addFeatureFlagsToUserAgent;
const constants_js_1 = require("./constants.js");
/**
 * @hidden
 */
function getUserAgent(optionsOrConnectionString, hostFramework) {
    let ua = `${userAgentDetails()} ${constants_js_1.Constants.SDKName}/${constants_js_1.Constants.SDKVersion}`;
    if (hostFramework) {
        ua = ua + " " + hostFramework;
    }
    if (optionsOrConnectionString && optionsOrConnectionString.userAgentSuffix) {
        ua = ua + " " + optionsOrConnectionString.userAgentSuffix;
    }
    return ua;
}
// TODO: Standardize across other platforms from @azure/core-util
function userAgentDetails() {
    let userAgentDetail = "<environment undetectable>";
    if (globalThis.navigator && globalThis.navigator.userAgent) {
        userAgentDetail = globalThis.navigator.userAgent;
    }
    if (globalThis.process && globalThis.process.version) {
        userAgentDetail = `Node.js/${process.version.slice(1)} (${process.platform}; ${process.arch})`;
    }
    return userAgentDetail;
}
/**
 * @hidden
 * TODO: This function was getting used to track PPAF. Now by default PPAF is enabled. We need to revisit this function.
 */
function addFeatureFlagsToUserAgent(optionsOrConnectionString) {
    let featureFlag = 0;
    if (optionsOrConnectionString.connectionPolicy) {
        if (optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover) {
            featureFlag += constants_js_1.UserAgentFeatureFlags.PerPartitionAutomaticFailover;
        }
        if (optionsOrConnectionString.connectionPolicy.enablePartitionLevelFailover ||
            optionsOrConnectionString.connectionPolicy.enablePartitionLevelCircuitBreaker) {
            featureFlag += constants_js_1.UserAgentFeatureFlags.PerPartitionCircuitBreaker;
        }
    }
    return featureFlag === 0 ? "" : ` F${featureFlag.toString(16).toUpperCase()}`;
}
//# sourceMappingURL=platform.js.map