'use strict';
const Joi = require('joi');
const { string, number } = Joi.types();
const fs = require('fs-extra');
const hdbTerms = require("../utility/hdbTerms.js");
const path = require('path');
const validator = require('../validation/validationWrapper.js');
module.exports = installValidator;
/**
 * Used to validate any command or environment variables used passed to install.
 * @param param
 * @returns {*}
 */
function installValidator(param) {
    const installSchema = Joi.object({
        [hdbTerms.INSTALL_PROMPTS.ROOTPATH]: Joi.custom(validateRootAvailable),
        [hdbTerms.INSTALL_PROMPTS.OPERATIONSAPI_NETWORK_PORT]: Joi.alternatives([number.min(0), string]).allow('null', null),
        [hdbTerms.INSTALL_PROMPTS.TC_AGREEMENT]: string.valid('yes', 'YES', 'Yes'),
    });
    return validator.validateBySchema(param, installSchema);
}
function validateRootAvailable(value, helpers) {
    if (fs.existsSync(path.join(value, 'system/hdb_user/data.mdb')) ||
        fs.existsSync(path.join(value, 'system/hdb_user.mdb'))) {
        return helpers.message(`'${value}' is already in use. Please enter a different path.`);
    }
}
//# sourceMappingURL=installValidator.js.map