import chalk from 'chalk';
import * as _ from 'lodash-es';
const { kebabCase, intersection } = _;
const includesValue = (prop, values) => answers => answers[prop] && intersection(answers[prop], values);
const command = {
    options: {},
    configs: {
        ciCd: {
            argument: {
                type: Array,
            },
            prompt: {
                type: 'checkbox',
                message: 'What CI/CD pipeline do you want to generate?',
            },
            choices: [
                { name: 'GitHub Actions', value: 'github' },
                { name: 'Jenkins pipeline', value: 'jenkins' },
                { name: 'GitLab CI', value: 'gitlab' },
                { name: 'Azure Pipelines', value: 'azure' },
                { name: 'Travis CI', value: 'travis' },
                { name: 'CircleCI', value: 'circle' },
            ],
            scope: 'generator',
        },
        ciCdIntegrations: {
            prompt: {
                type: 'checkbox',
                message: 'What tasks/integrations do you want to include ?',
            },
            choices: [
                { name: `Deploy your application to an ${chalk.yellow('*Artifactory*')}`, value: 'deploy' },
                { name: `Analyze your code with ${chalk.yellow('*Sonar*')}`, value: 'sonar' },
                { name: `Build and publish a ${chalk.yellow('*Docker*')} image`, value: 'publishDocker' },
                {
                    name: `${chalk.yellow('*Snyk*')}: dependency scanning for security vulnerabilities (requires SNYK_TOKEN)`,
                    value: 'snyk',
                },
                {
                    name: `Deploy to ${chalk.yellow('*Heroku*')} (requires HEROKU_API_KEY set on CI service)`,
                    value: 'heroku',
                },
                {
                    name: `Would you like to enable the ${chalk.yellow('*Cypress Dashboard*')} (requires both CYPRESS_PROJECT_ID and CYPRESS_RECORD_KEY set on CI service)`,
                    value: 'cypressDashboard',
                },
            ],
            scope: 'generator',
        },
        insideDocker: {
            prompt: {
                when: includesValue('ciCd', ['jenkins', 'gitlab']),
                type: 'confirm',
                message: 'Would you like to perform the build in a Docker container ?',
                default: false,
            },
            scope: 'generator',
        },
        sendBuildToGitlab: {
            prompt: {
                when: includesValue('ciCd', ['jenkins']),
                type: 'confirm',
                message: 'Would you like to send build status to GitLab ?',
                default: false,
            },
            scope: 'generator',
        },
        artifactorySnapshotsId: {
            prompt: {
                when: includesValue('ciCdIntegrations', ['deploy']),
                type: 'input',
                message: `${chalk.yellow('*Artifactory*')}: what is the ID of distributionManagement for snapshots ?`,
            },
            default: 'snapshots',
            scope: 'generator',
        },
        artifactorySnapshotsUrl: {
            prompt: {
                when: includesValue('ciCdIntegrations', ['deploy']),
                type: 'input',
                message: `${chalk.yellow('*Artifactory*')}: what is the URL of distributionManagement for snapshots ?`,
            },
            default: 'http://artifactory:8081/artifactory/libs-snapshot',
            scope: 'generator',
        },
        artifactoryReleasesId: {
            prompt: {
                when: includesValue('ciCdIntegrations', ['deploy']),
                type: 'input',
                message: `${chalk.yellow('*Artifactory*')}: what is the ID of distributionManagement for releases ?`,
            },
            default: 'releases',
            scope: 'generator',
        },
        artifactoryReleasesUrl: {
            prompt: {
                when: includesValue('ciCdIntegrations', ['deploy']),
                type: 'input',
                message: `${chalk.yellow('*Artifactory*')}: what is the URL of distributionManagement for releases ?`,
            },
            default: 'http://artifactory:8081/artifactory/libs-release',
            scope: 'generator',
        },
        sonarName: {
            prompt: {
                when: answers => includesValue('ciCd', ['jenkins'])(answers) && includesValue('ciCdIntegrations', ['ciCdIntegrations'])(answers),
                type: 'input',
                message: `${chalk.yellow('*Sonar*')}: what is the name of the Sonar server ?`,
            },
            default: 'sonar',
            scope: 'generator',
        },
        sonarUrl: {
            prompt: {
                when: answers => includesValue('ciCd', ['jenkins'])(answers) && includesValue('ciCdIntegrations', ['ciCdIntegrations'])(answers),
                type: 'input',
                message: `${chalk.yellow('*Sonar*')}: what is the URL of the Sonar server ?`,
            },
            default: 'https://sonarcloud.io',
            scope: 'generator',
        },
        sonarOrga: {
            prompt: {
                when: answers => includesValue('ciCd', ['jenkins'])(answers) && includesValue('ciCdIntegrations', ['ciCdIntegrations'])(answers),
                type: 'input',
                message: `${chalk.yellow('*Sonar*')}: what is the Organization of the Sonar server ?`,
            },
            scope: 'generator',
        },
        dockerImage: {
            prompt: ({ jhipsterConfigWithDefaults: config }) => ({
                when: answers => includesValue('ciCd', ['github'])(answers) && includesValue('ciCdIntegrations', ['publishDocker'])(answers),
                type: 'input',
                message: `${chalk.yellow('*Docker*')}: what is the name of the image ?`,
                default: () => `jhipster/${config.dasherizedBaseName}`,
            }),
            scope: 'generator',
        },
        herokuAppName: {
            prompt: {
                when: includesValue('ciCdIntegrations', ['heroku']),
                type: 'input',
                message: `${chalk.yellow('*Heroku*')}: name of your Heroku Application ?`,
            },
            scope: 'generator',
            default: config => kebabCase(config.jhipsterConfigWithDefaults.baseName),
        },
    },
};
export default command;
