"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setNonInteractive = setNonInteractive;
exports.promptRename = promptRename;
exports.promptMigrationDescription = promptMigrationDescription;
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
const readline_1 = require("readline");
let nonInteractive = false;
function setNonInteractive(value) {
    nonInteractive = value;
}
setNonInteractive.__type = ['value', 'setNonInteractive', 'P)2!$/"'];
async function promptRename(tableName, newName, oldCandidates) {
    if (nonInteractive)
        return null;
    if (oldCandidates.length === 1) {
        const oldName = oldCandidates[0];
        const answer = await ask(`Table \`${tableName}\`: Column \`${oldName}\` was removed and \`${newName}\` was added.\n` +
            `Was \`${oldName}\` renamed to \`${newName}\`? [y/N] `);
        return answer.toLowerCase() === 'y' ? oldName : null;
    }
    // Multiple candidates
    console.log(`\nTable \`${tableName}\`: Column \`${newName}\` was added and these columns were removed:`);
    for (let i = 0; i < oldCandidates.length; i++) {
        console.log(`  ${i + 1}. ${oldCandidates[i]}`);
    }
    console.log(`  0. None (treat as new column)`);
    const answer = await ask(`Was \`${newName}\` renamed from one of these? [0-${oldCandidates.length}] `);
    const choice = parseInt(answer, 10);
    if (isNaN(choice) || choice === 0 || choice > oldCandidates.length)
        return null;
    return oldCandidates[choice - 1];
}
promptRename.__type = ['tableName', 'newName', 'oldCandidates', 'promptRename', 'P&2!&2"&F2#P&,J`/$'];
async function promptMigrationDescription() {
    if (nonInteractive)
        return 'auto';
    const answer = await ask('Enter a short description for this migration: ');
    return answer.trim() || 'migration';
}
promptMigrationDescription.__type = ['promptMigrationDescription', 'P&`/!'];
function ask(question) {
    const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout });
    return new Promise(__assignType(resolve => {
        rl.question(question, __assignType(answer => {
            rl.close();
            resolve(answer);
        }, ['answer', '', 'P"2!"/"']));
    }, ['resolve', '', 'P"2!"/"']));
}
ask.__type = ['question', 'ask', 'P&2!&`/"'];
//# sourceMappingURL=prompt.js.map