
const inquirer = require('inquirer')
module.exports =  {
    async createProject(){
        const languages = [
            { name: 'Nodejs', value: 'nodejs' },
            { name: 'Php', value: 'php' },
            { name: 'Java', value: 'java' },
            { name: 'Python', value: 'python' },
        ]
        const frameworks = {
            'nodejs': [
                { name: 'koa1', value: 'koa1' },
                { name: 'koa2', value: 'koa2' },
                { name: 'express1', value: 'express1' },
                { name: 'express2', value: 'express2' },
                // { name: 'express', value: 'express' }
            ],
            'php': [
                { name: 'laravel', value: 'laravel' },
                // { name: 'thinkphp', value: 'thinkphp' },
            ],
            'java': [
                // { name: 'Spring Boot', value: 'Spring Boot' }
                { name: 'springboot1', value: 'springboot1' },
                { name: 'springboot2', value: 'springboot2' },
                { name: 'ssm1', value: 'ssm1' },
                { name: 'ssm2', value: 'ssm2' },
            ],
            'python': [
                { name:'django1', value: 'django1' }
            ]
        }
    
        const databaseTypes = [
            { name: 'MySQL', value: 'mysql' },
            // { name: 'MongoDB', value: 'mongodb' }
        ]
    
        const webFrameworks = [
            { name: 'vue', value: 'vue' },
            // { name: 'react', value: 'react' }
        ]
    
        const { projectTitle } = await inquirer.prompt([
            {
              name: 'projectTitle',
              type: 'input',
              message: `请输入毕设题目`,
            }
        ])
        if (!projectTitle) return;
    

        const { language } = await inquirer.prompt([
            {
              name: 'language',
              type: 'list',
              message: `请选择项目开发语言（Choose a development language）`,
              choices: languages
            }
        ])
        if (!language) return;
    
    
        const { framework } = await inquirer.prompt([
            {
                name: 'framework',
                type: 'list',
                message: `请选择语言框架（Choose the framework）`,
                choices: frameworks[language] 
            }
        ])
      
        if(!framework) return;
        const { databaseType } = await inquirer.prompt([
            {
                name: 'databaseType',
                type: 'list',
                message: `请选择数据库（Select the database type）`,
                choices: databaseTypes
            }
        ])
        if (!databaseType) return;

        let { databaseHost } = await inquirer.prompt([
            {
              name: 'databaseHost',
              type: 'input',
              message: `请输入数据库地址(默认localhost)`,
            }
        ])
        if (!databaseHost) {
            databaseHost = 'localhost'
        }

        let { databasePort } = await inquirer.prompt([
            {
              name: 'databasePort',
              type: 'input',
              message: `请输入数据库端口(默认3306)`,
            }
        ])
        if (!databasePort) {
            databasePort = '3306'
        }

        let { databaseUser } = await inquirer.prompt([
            {
              name: 'databaseUser',
              type: 'input',
              message: `请输入数据库用户名(默认 root)`,
            }
        ])
        if (!databaseUser) {
            databaseUser = 'root'
        }


        let { databasePassword } = await inquirer.prompt([
            {
              name: 'databasePassword',
              type: 'input',
              message: `请输入数据库密码(默认root)`,
            }
        ])
        if (!databasePassword) {
            databasePassword = 'root'
        }
    
        // const { webFramework } = await inquirer.prompt([
        //     {
        //         name: 'webFramework',
        //         type: 'list',
        //         message: `Select the web framework`,
        //         choices: webFrameworks
        //     }
        // ])
        // if (!webFramework) return;
    
    
    
    
        return { language, framework, databaseType, projectTitle,databaseHost ,databasePort , databaseUser, databasePassword }
    },
    async createApi(){
        const isSureOptions = [
            { name: '继续', value:'yes'},
            { name: '取消', value: 'no' },
        ]
        const { isSure } = await inquirer.prompt([
            {
              name: 'isSure',
              type: 'list',
              message: `该操作会覆盖控制器，模型，是否继续？`,
              choices: isSureOptions
            }
        ])
        if (!isSure) return;

        return { isSure }
    },
    async createView(){
        const isSureOptions = [
            { name: '继续', value:'yes'},
            { name: '取消', value: 'no' },
        ]
        const languages = [
            { name: '简体中文', value: 'zh' },
            { name: '英文', value: 'en' },
        ]
        const projects = [
           { name: '简单模式', value: 'simple'},
           { name: '标准模式', value: 'common'}
        ]
        const layouts = [
            { name: ` 纵向（F）`, value: 'vertical'},
            { name: ` 经典`, value: 'classic'},
            { name: ` 横向（二）`, value: 'transverse'},
            { name: '分栏（| | |）', value: 'columns'}
         ]
         const templates = [
            { name: `default`, value: 'generator-cms-template'},
            { name: `template-2`, value: 'generator-cms-template-2'},
            { name: `template-3`, value: 'generator-cms-template-3'},
            { name: `template-4`, value: 'generator-cms-template-4'},
            { name: `template-5`, value: 'generator-cms-template-5'},
            { name: `template-6`, value: 'generator-cms-template-6'},
            { name: `template-7`, value: 'generator-cms-template-7'},
         ]
        const { isSure } = await inquirer.prompt([
            {
              name: 'isSure',
              type: 'list',
              message: `该操作会覆盖视图文件是否继续？`,
              choices: isSureOptions
            }
        ])
        if (!isSure) return;

        const { template } = await inquirer.prompt([
            {
              name: 'template',
              type: 'list',
              message: `请选择基础模板`,
              choices: templates
            }
        ])
        if (!template) return;

        // const { type } = await inquirer.prompt([
        //     {
        //       name: 'type',
        //       type: 'list',
        //       message: `请选择项目复杂度`,
        //       choices: projects
        //     }
        // ])
        // if (!type) return;

        // const { layout } = await inquirer.prompt([
        //     {
        //       name: 'layout',
        //       type: 'list',
        //       message: `请选择项目布局方式`,
        //       choices: layouts
        //     }
        // ])
        // if (!layout) return;

        return { isSure, template }
    }
}
