"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.COMMANDS = void 0;
const commands_1 = __importDefault(require("./constants/commands"));
const www_1 = require("./init/www");
const utils_1 = require("./utils");
const packageJson = { version: "5.0.4" };
const EInit = {
    CREATE: 0,
    PROJECT_NAME: 2,
    DBNAME: 4,
    __NAME: 1,
    __DB: 3,
};
const COMMANDS = ({ cmd }) => __awaiter(void 0, void 0, void 0, function* () {
    switch (cmd[EInit.CREATE]) {
        case commands_1.default.SETUP.NODE:
            if (commands_1.default.__name === cmd[EInit.__NAME]) {
                if (!cmd[EInit.PROJECT_NAME]) {
                    utils_1.logger.error(`App name should be required`);
                }
                else {
                    if (commands_1.default.__db === cmd[EInit.__DB]) {
                        if (cmd[EInit.DBNAME] &&
                            (cmd[EInit.DBNAME] === commands_1.default.DBS.MONGOD ||
                                cmd[EInit.DBNAME] === commands_1.default.DBS.MYSQL ||
                                cmd[EInit.DBNAME] === commands_1.default.DBS.PSQL ||
                                cmd[EInit.DBNAME] === commands_1.default.DBS.CARE_PSQL)) {
                            switch (cmd[EInit.DBNAME]) {
                                case commands_1.default.DBS.MYSQL:
                                    yield (0, www_1.createServerFolders)({
                                        appName: cmd[EInit.PROJECT_NAME],
                                        rname: "mysql1",
                                    });
                                    break;
                                case commands_1.default.DBS.PSQL:
                                    yield (0, www_1.createServerFolders)({
                                        appName: cmd[EInit.PROJECT_NAME],
                                        rname: "mysql1",
                                    });
                                    break;
                                case commands_1.default.DBS.CARE_PSQL:
                                    yield (0, www_1.createServerFolders)({
                                        appName: cmd[EInit.PROJECT_NAME],
                                        rname: "exsp_postgresql",
                                    });
                                    break;
                                default:
                                    yield (0, www_1.createServerFolders)({
                                        appName: cmd[EInit.PROJECT_NAME],
                                        rname: "exsp4",
                                    });
                                    break;
                            }
                        }
                        else {
                            utils_1.logger.error(`Database type must be these ${commands_1.default.DBS.MONGOD}, ${commands_1.default.DBS.MYSQL}, ${commands_1.default.DBS.PSQL}   `);
                        }
                    }
                    else {
                        utils_1.logger.error(`Invalid command`);
                    }
                }
            }
            else {
                utils_1.logger.error(`${cmd[EInit.__NAME]} : Command Not Found!`);
            }
            break;
        case commands_1.default.SETUP.REACT:
            utils_1.logger.error(`${cmd[EInit.CREATE]} release comming soon...`);
            break;
        case commands_1.default.SETUP.PYTHON:
            utils_1.logger.error(`${cmd[EInit.CREATE]} release comming soon...`);
            break;
        case commands_1.default.version:
            utils_1.logger.verson(`v${packageJson.version}`);
            break;
        case commands_1.default.v:
            utils_1.logger.verson(`v${packageJson.version}`);
            break;
        default:
            utils_1.logger.error(`${cmd[EInit.CREATE]} : Command Not Found!`);
    }
});
exports.COMMANDS = COMMANDS;
