/**
 * Module configuration parameters
 */

const convict = require ('convict');

const config = convict ({
  env: {
    doc: 'The application environment.',
    format: ['production', 'development', 'test'],
    default: 'development',
    env: 'NODE_ENV'
  },
  openfaasurl: {
    doc: 'OpenFaaS URL.',
    format: 'url',
    default: 'http://0.0.0.0:8080',
    env: 'OPENFAAS_URL',
    arg: 'openfaasurl'
  },
  openfaasusername: {
    doc: 'OpenFaaS admin username.',
    format: '*',
    default: 'admin',
    env: 'OPENFAAS_USERNAME',
    arg: 'openfaasusername'
  },
  openfaaspassword: {
    doc: 'OpenFaaS admin password.',
    format: '*',
    default: 'admin',
    env: 'OPENFAAS_PASSWORD',
    arg: 'openfaaspassword'
  },
  activemqurl: {
    doc: 'ActiveMQ URL.',
    format: 'url',
    default: 'http://172.21.0.2:61613',
    env: 'ACTIVEMQ_URL',
    arg: 'activemqurl'
  },
  bodysizelimit: {
    doc: 'Event generator POST body size limits.',
    format: '*',
    default: '50mb',
    env: 'BODYSIZE_LIMIT',
    arg: 'bodysizelimit'
  },
  activemqusername: {
    doc: 'ActiveMQ username.',
    format: 'url',
    default: 'guest',
    env: 'ACTIVEMQ_USERNAME',
    arg: 'activemqusername'
  },
  activemqpassword: {
    doc: 'ActiveMQ password.',
    format: '*',
    default: 'guest',
    env: 'ACTIVEMQ_PASSWORD',
    arg: 'activemqpassword'
  },
  activemqversion: {
    doc: 'ActiveMQ version.',
    format: ['1.0', '1.1'],
    default: '1.1',
    env: 'ACTIVEMQ_VERSION',
    arg: 'activemqversion'
  },
  activemqvhost: {
    doc: 'ActiveMQ vhost.',
    format: '*',
    default: null,
    env: 'ACTIVEMQ_VHOST',
    arg: 'activemqvhost'
  },
  activemqretries: {
    doc: 'ActiveMQ maximum number of reconnection attempt.',
    format: 'int',
    default: 10,
    env: 'ACTIVEMQ_RETRIES',
    arg: 'activemqretries'
  },
  activemqdelay: {
    doc: 'ActiveMQ reconnection delay in millisenconds.',
    format: 'int',
    default: 2000,
    env: 'ACTIVEMQ_DELAY',
    arg: 'activemqdelay'
  },
  activemqcontenttype: {
    doc: 'ActiveMQ messages content type.',
    format: '*',
    default: 'application/json',
    env: 'ACTIVEMQ_CONTENTTYPE',
    arg: 'activemqcontenttype'
  },
  activemqack: {
    doc: 'ActiveMQ acknoweledgment type.',
    format: '*',
    default: 'client',
    env: 'ACTIVEMQ_ACK',
    arg: 'activemqack'
  },
  activemqsendack: {
    doc: 'Flag that signals whether to send the ack, nack, or nothing at all.',
    format: ['ack', 'nack', 'none'],
    default: 'ack',
    env: 'ACTIVEMQ_SENDACK',
    arg: 'activemqsendack'
  },
  generatorport: {
    doc: 'Generator port',
    format: 'port',
    default: 5010,
    env: 'GENERATOR_PORT',
    arg: 'generatorport'
  },
  generatorhost: {
    doc: 'Generator hostname.',
    format: 'ipaddress',
    default: '128.250.7.79',
    env: 'GENERATOR_HOST',
    arg: 'generatorhost'
  },
  functionannotationrequestqueue: {
    doc: 'OpenFaaS function annotation to hook it to a queue for requests.',
    format: '*',
    default: 'OpenFaasQueueRequest',
    env: 'FUNCTION_ANNOTATION_QUEUEREQUEST',
    arg: 'functionannotationrequestqueue'
  },
  functionannotationresponsequeue: {
    doc: 'OpenFaaS function annotation to hook it to a queue for responses.',
    format: '*',
    default: 'OpenFaasQueueResponse',
    env: 'FUNCTION_ANNOTATION_QUEUERESPONSE',
    arg: 'functionannotationresponsequeue'
  },
  functionannotationrequesttopics: {
    doc: 'OpenFaaS function annotation to hook it to (comma-separated) topic list for requests.',
    format: '*',
    default: 'OpenFaasTopicsRequest',
    env: 'FUNCTION_ANNOTATION_TOPICSREQUEST',
    arg: 'functionannotationrequesttopics'
  },
  functionannotationresponsetopics: {
    doc: 'OpenFaaS function annotation to hook it to (comma-separated) topic list for responses.',
    format: '*',
    default: 'OpenFaasTopicsResponse',
    env: 'FUNCTION_ANNOTATION_TOPICSRESPONSE',
    arg: 'functionannotationresponsetopics'
  },
  functionpollinginterval: {
    doc: 'OpenFaaS API polling interval in milliseconds.',
    format: 'int',
    default: 20000,
    env: 'FUNCTION_POLLING_INTERVAL',
    arg: 'functionpollinginterval'
  },
  loglevel: {
    doc: 'The log level.',
    format: ['debug', 'info', 'warn', 'error', 'fail'],
    default: 'info',
    env: 'LOGLEVEL',
    arg: 'loglevel'
  },
  logtype: {
    doc: 'The log type.',
    format: ['stdout', 'file'],
    default: 'stdout',
    env: 'LOGTYPE',
    arg: 'logtype'
  },
  logfile: {
    doc: 'The complete log file path.',
    format: '*',
    default: '/tmp/eventgenerator.log',
    env: 'LOGFILE',
    arg: 'logfile'
  },
  requestqueue: {
    doc: 'ActiveMQ request queue (used for system tests).',
    format: '*',
    default: '/queue/ofreq',
    env: 'REQUEST_QUEUE',
    arg: 'requestqueue'
  },
  responsequeue: {
    doc: 'ActiveMQ response queue (used for system tests).',
    format: '*',
    default: '/queue/ofres',
    env: 'RESPONSE_QUEUE',
    arg: 'responsequeue'
  },
  producerport: {
    doc: 'Producer port (used for system tests).',
    format: 'port',
    default: 3003,
    env: 'PRODUCER_PORT',
    arg: 'producerport'
  }
});

config.loadFile ('./config/' + config.get ('env') + '.json');
config.validate ({allowed: 'strict'});

module.exports = config;
