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

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

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,
  features: {
    __VERSION__: JSON.stringify(`v${require('./package.json').version}.${getTimestamp()}`),
    // 未开发完的路由
    __DEV__: !isProd,
    // 待测试的功能
    __STAGING__: !isProd || isStaging,
    // 未开发的功能组件
    ...isEnable('__PLACEHOLDER__'),
    // 传感器
    ...isEnable('__SENSOR__'),
    // 摄像头
    ...isEnable('__CAMERA__')
  }
}
