"use strict";

var convict = require('convict');

var serverEnv = "WEB_APP_SERVER";

if (process.env.GOBBLE_SERVER) {
    serverEnv = "GOBBLE_SERVER";
}

/*eslint-disable */
var conf = convict({
    env: {
        doc: "The applicaton environment.",
        format: ["production", "development", "test"],
        default: "development",
        env: "NODE_ENV"
    },
    serv: {
        doc: "The Server environment.",
        format: "*",
        default: "development",
        env: serverEnv
    },
    log: {
        main: {
            doc: "The main log file path.",
            format: "*",
            default: null,
            env: "LOG_MAIN_FILE_PATH"
        },
        db: {
            doc: "The database log file path.",
            format: "*",
            default: null,
            env: "LOG_DB_FILE_PATH"
        },
        ftSearch: {
            doc: "The search log file path.",
            format: "*",
            default: null,
            env: "LOG_SEARCH_FILE_PATH"
        },
        test: {
            doc: "The test log file path.",
            format: "*",
            default: null,
            env: "LOG_TEST_FILE_PATH"
        },
        auth: {
            doc: "The auth log file path.",
            format: "*",
            default: null,
            env: "LOG_AUTH_FILE_PATH"
        },
        webAppError: {
            doc: "The web app error log file path.",
            format: "*",
            default: null,
            env: "LOG_WEB_APP_ERROR_PATH"
        },
        maxSize: {
            doc: "The maximum size of log file.",
            format: "int",
            default: "1048576",
            env: "LOG_MAX_SIZE"
        },
        maxFileCount: {
            doc: "The maximum number of log files to keep.",
            format: "int",
            default: 5,
            env: "LOG_MAX_FILE_KEEP"
        },
        level: {
            doc: "The log level",
            format: ["silly", "debug", "verbose", "info", "warn", "error"],
            default: "debug",
            env: "LOG_LEVEL"
        },
        dateFormat: {
            doc: "The log date format.",
            format: String,
            default: "YYYY-MM-DD HH:mm Z",
            env: "LOG_DATE_FORMAT"
        },
        enableConsole: {
            doc: "Whether to output the log to the console",
            format: Boolean,
            default: true,
            env: "LOG_ENABLE_CONSOLE"
        },
        logStash: {
            format: "*",
            default: null
        }
    }
});
/*eslint-enable */

// load environment dependent configuration

var serv = conf.get('serv');
conf.loadFile('./server/config/' + serv + '_log.json');

// perform validation

conf.validate();

module.exports = conf;