const path = require('path')

/**
 * ServiceConfig
 *
 * Centralizes environment parsing and default values.
 */
class ServiceConfig {
  constructor(env = process.env) {
    this._env = env
  }

  /**
   * @returns {{port: number, pageSize: number, refreshCron: string, dataDirectory: string}}
   */
  toRuntimeConfig() {
    return {
      port: Number(this._env.PORT || 3100),
      pageSize: Number(this._env.NEWS_PAGE_SIZE || 20),
      refreshCron: this._env.NEWS_REFRESH_CRON || '0 * * * *',
      dataDirectory: path.resolve(process.cwd(), this._env.DATA_DIR || './data')
    }
  }
}

module.exports = {
  ServiceConfig
}
