import chalk from 'chalk';
import { createJHipsterLogger, CLI_LOGGER } from '../generators/base/support/index.mjs';
export const CLI_NAME = 'begcode';
export const GENERATOR_NAME = 'generator-begcode';
const SUCCESS_MESSAGE = `Congratulations, BegCode execution is complete!
If you find BegCode useful consider sponsoring the project ${chalk.yellow('https://www.begcode.com/sponsors.html')}`;
const SPONSOR_MESSAGE = 'Thanks for using BegCode!';
export const logger = createJHipsterLogger({ namespace: CLI_LOGGER });
export const getCommand = (cmd, args = []) => {
    let cmdArgs;
    if (args.length > 0) {
        logger.debug('Arguments found');
        args = args.flat();
        cmdArgs = args.join(' ').trim();
        logger.debug(`cmdArgs: ${cmdArgs}`);
    }
    return `${cmd}${cmdArgs ? ` ${cmdArgs}` : ''}`;
};
export const doneFactory = (successMsg, sponsorMsg) => {
    return errorOrMsg => {
        if (errorOrMsg instanceof Error) {
            logger.error(`ERROR! ${errorOrMsg.message}`);
            logger.log(errorOrMsg);
        }
        else if (errorOrMsg) {
            logger.error(`ERROR! ${errorOrMsg}`);
        }
        else if (successMsg) {
            logger.log('');
            logger.log(chalk.green.bold(successMsg));
            logger.log('');
            logger.log(chalk.cyan.bold(sponsorMsg));
        }
    };
};
export const printSuccess = () => {
    if (process.exitCode === undefined || process.exitCode === 0) {
        logger.log('');
        logger.log(chalk.green.bold(SUCCESS_MESSAGE));
        logger.log('');
        logger.log(chalk.cyan.bold(SPONSOR_MESSAGE));
    }
    else {
        logger.error(`BegCode finished with code ${process.exitCode}`);
    }
};
export const done = doneFactory(SUCCESS_MESSAGE, SPONSOR_MESSAGE);
