"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.promptInitOptions = promptInitOptions;
exports.promptOverwrite = promptOverwrite;
const inquirer_1 = __importDefault(require("inquirer"));
const projectApi_1 = require("./projectApi");
const cache_1 = require("./cache");
async function promptInitOptions(projectName) {
    const questions = [];
    // 检查缓存的 authorization
    const cachedAuth = await (0, cache_1.getAuthorization)();
    // 1. 授权信息
    questions.push({
        type: 'input',
        name: 'authorization',
        message: '请输入授权信息 (authorization):',
        default: cachedAuth || '',
        validate: (input) => {
            if (!input.trim()) {
                return 'authorization 不能为空';
            }
            return true;
        },
    }, 
    // 2. 项目描述
    {
        type: 'input',
        name: 'description',
        message: '请输入项目描述:',
        validate: (input) => {
            if (!input.trim()) {
                return '项目描述不能为空';
            }
            return true;
        },
    }, 
    // 3. 版本说明
    {
        type: 'input',
        name: 'minorVersionDescription',
        message: '请输入 Minor 版本说明:',
        default: '',
    }, {
        type: 'input',
        name: 'revisionVersionDescription',
        message: '请输入 Revision 版本说明:',
        default: '',
    }, 
    // 4. 作者
    {
        type: 'input',
        name: 'author',
        message: '作者名称 (可选):',
        default: '',
    });
    let answers = await inquirer_1.default.prompt(questions);
    // 保存 authorization 到缓存
    await (0, cache_1.saveAuthorization)(answers.authorization);
    // 5. 获取应用列表并让用户选择
    let appId = '';
    let appName = '';
    try {
        const appOptions = await (0, projectApi_1.getAppOptions)(answers.authorization);
        if (appOptions && appOptions.length > 0) {
            const { selectedApp } = await inquirer_1.default.prompt({
                type: 'list',
                name: 'selectedApp',
                message: '请选择应用:',
                choices: appOptions.map(app => ({
                    name: app.label,
                    value: `${app.id}|${app.label}`,
                })),
                default: appOptions[0] ? `${appOptions[0].id}|${appOptions[0].label}` : '',
            });
            const [id, name] = selectedApp.split('|');
            appId = id;
            appName = name;
        }
    }
    catch (error) {
        console.log('获取应用列表失败，将使用默认应用');
    }
    return {
        authorization: answers.authorization,
        description: answers.description,
        minorVersionDescription: answers.minorVersionDescription,
        revisionVersionDescription: answers.revisionVersionDescription,
        author: answers.author,
        appId,
        appName,
    };
}
async function promptOverwrite() {
    const { overwrite } = await inquirer_1.default.prompt({
        type: 'confirm',
        name: 'overwrite',
        message: '目标目录已存在，是否覆盖？',
        default: false,
    });
    return overwrite;
}
//# sourceMappingURL=prompt.js.map