"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NxKeyNotInstalledError = void 0;
exports.printNxKey = printNxKey;
exports.getNxKeyInformation = getNxKeyInformation;
const logger_1 = require("./logger");
const package_manager_1 = require("./package-manager");
const workspace_root_1 = require("./workspace-root");
async function printNxKey() {
    try {
        const { organizationName, seatCount, workspaceCount } = await getNxKeyInformation();
        logger_1.logger.log(`Nx key licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? 's' : ''} in ${workspaceCount === 9999 ? 'an unlimited number of' : workspaceCount} workspace${workspaceCount > 1 ? 's' : ''}`);
    }
    catch { }
}
async function getNxKeyInformation() {
    try {
        const { getPowerpackLicenseInformation, getPowerpackLicenseInformationAsync, } = (await Promise.resolve().then(() => require('@nx/powerpack-license')));
        return (getPowerpackLicenseInformationAsync ?? getPowerpackLicenseInformation)(workspace_root_1.workspaceRoot);
    }
    catch (e) {
        try {
            const { getNxKeyInformationAsync } = (await Promise.resolve().then(() => require('@nx/key')));
            return getNxKeyInformationAsync(workspace_root_1.workspaceRoot);
        }
        catch (e) {
            if ('code' in e && e.code === 'MODULE_NOT_FOUND') {
                throw new NxKeyNotInstalledError(e);
            }
            throw e;
        }
    }
}
class NxKeyNotInstalledError extends Error {
    constructor(e) {
        super(`The "@nx/key" package is needed to use Nx key enabled features. Please install it with ${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/key`, { cause: e });
    }
}
exports.NxKeyNotInstalledError = NxKeyNotInstalledError;
