const isProd = process.env.NODE_ENV !== 'development'
const isStaging = process.env.ENV === 'staging'

function isEnable (feature) {
  return !isProd || process.env[feature] === 'enabled'
}

function createFeature (feature) {
  return { [feature]: isEnable(feature) }
}

function getTimestamp () {
  const now = new Date()
  return `${now.getFullYear()}${(now.getMonth() + 1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}${now.getHours().toString().padStart(2, '0')}${now.getMinutes().toString().padStart(2, '0')}${now.getSeconds().toString().padStart(2, '0')}`
}

module.exports = {
  isProd,
  isStaging,
  logger: isStaging || isEnable('LOGGER'),
  features: {
    __VERSION__: JSON.stringify(`v${require('./package.json').version}.${getTimestamp()}`),
    __DEV__: !isProd,
    __STAGING__: !isProd || isStaging,
    ...createFeature('__PLACEHOLDER__'),
    ...createFeature('__SENSOR__'),
    ...createFeature('__DEVICE_DASHBARD__'),
    ...createFeature('__TAKEOVER__')
  }
}
