'use strict';
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.forceDowngradePrompt = forceDowngradePrompt;
exports.upgradeCertsPrompt = upgradeCertsPrompt;
const prompt_1 = __importDefault(require("prompt"));
const chalk_1 = __importDefault(require("chalk"));
const os = __importStar(require("os"));
const assignCmdEnvVariables_ts_1 = __importDefault(require("../utility/assignCmdEnvVariables.js"));
const UPGRADE_PROCEED = ['yes', 'y'];
/**
 * Prompt the user before proceeding with a minor version downgrade
 * @param _upgradeObj - {UpgradeObject} Object includes the versions the data and current install are on
 * @returns {Promise<boolean>}
 */
async function forceDowngradePrompt(_upgradeObj) {
    let downgradeMessage = `${os.EOL}` +
        chalk_1.default.bold.green('Your installed Harper version is older than the version used to create your data.' +
            ' Downgrading is not recommended as it is not tested and guaranteed to work. However, if you need to' +
            ' downgrade, and a backup of your data has not been created, we recommend you cancel this process and' +
            ' backup before proceeding.' +
            `${os.EOL}`);
    prompt_1.default.override = (0, assignCmdEnvVariables_ts_1.default)(['CONFIRM_DOWNGRADE']);
    prompt_1.default.start();
    prompt_1.default.message = downgradeMessage;
    let downgradeConfirmation = {
        properties: {
            CONFIRM_DOWNGRADE: {
                description: chalk_1.default.magenta(`${os.EOL}[CONFIRM_DOWNGRADE] Do you want to proceed with using your downgraded HDB instance now? (yes/no)`),
                pattern: /y(es)?$|n(o)?$/,
                message: "Must respond 'yes' or 'no'",
                default: 'no',
                required: true,
            },
        },
    };
    let response = await prompt_1.default.get([downgradeConfirmation]);
    return UPGRADE_PROCEED.includes(response.CONFIRM_DOWNGRADE);
}
async function upgradeCertsPrompt() {
    const upgradeCertMessage = `${os.EOL}` +
        chalk_1.default.bold.green('We now require a Certifacte Authority certificate. Harper can generate all new certificates for you (your existing certificates will be backed up) ' +
            'or you can keep any existing certificates and add your own CA certificate. To add your own CA certificate set the <certificateAuthority> ' +
            'parameter in harperdb-config.yaml');
    prompt_1.default.override = (0, assignCmdEnvVariables_ts_1.default)(['GENERATE_CERTS']);
    prompt_1.default.start();
    prompt_1.default.message = upgradeCertMessage;
    let upgradeConfirmation = {
        properties: {
            GENERATE_CERTS: {
                description: chalk_1.default.magenta(`${os.EOL}[GENERATE_CERTS] Do you want Harper to generate all new certificates? (yes/no)`),
                pattern: /y(es)?$|n(o)?$/,
                message: "Must respond 'yes' or 'no'",
                default: 'yes',
                required: true,
            },
        },
    };
    const response = await prompt_1.default.get([upgradeConfirmation]);
    return UPGRADE_PROCEED.includes(response.GENERATE_CERTS);
}
//# sourceMappingURL=upgradePrompt.js.map