/* Note: do not use ES6 features here, we need to use this module from the build system before translation */
const convict = require("convict");
const envc = require("envc");
const path = require("path");

// Populate `process.env` with overrides from environment-specific `.env`
// files as a side effect. See `https://npmjs.org/envc` for more info.
envc({booleans: true});

var conf = convict({
  port: {
    doc: "The PageShot server port",
    format: "port",
    default: 10080,
    env: "PORT",
    arg: "port"
  },
  siteOrigin: {
    doc: "The server public origin (except protocol)",
    format: String,
    default: "localhost:10080",
    env: "SITE_ORIGIN",
    arg: "siteOrigin"
  },
  contentPort: {
    doc: "The content server port",
    format: "port",
    default: 10081,
    env: "CONTENT_PORT",
    arg: "contentPort"
  },
  contentOrigin: {
    doc: "The content server public origin (except protocol)",
    format: String,
    default: "localhost:10081",
    env: "CONTENT_ORIGIN",
    arg: "contentOrigin"
  },
  useVirtualHosts: {
    doc: "If true, use the main site port for the content server, and ignore contentPort. Virtual hosts will be used for SITE_ORIGIN and CONTENT_ORIGIN.",
    format: Boolean,
    default: false,
    env: "USE_VIRTUAL_HOSTS",
    arg: "useVirtualHosts"
  },
  useS3: {
    doc: "If true, store files in s3. If false, store them locally",
    format: Boolean,
    default: false,
    env: "USE_S3",
    arg: "useS3"
  },
  s3BucketName: {
    doc: "The name of the bucket to use on s3, if useS3 is true",
    format: String,
    default: "pageshot-images-bucket",
    env: "S3_BUCKET_NAME",
    arg: "s3BucketName"
  },
  oAuth: {
    oAuthServer: {
      doc: "The FxA OAuth server base URL",
      format: String,
      default: "https://oauth-stable.dev.lcip.org/v1",
      env: "OAUTH_SERVER",
      arg: "oauth-server",
    },
    contentServer: {
      doc: "The FxA content server base URL",
      format: String,
      default: "https://stable.dev.lcip.org",
      env: "CONTENT_SERVER",
      arg: "content-server",
    },
    profileServer: {
      doc: "The FxA profile server base URL",
      format: String,
      default: "https://stable.dev.lcip.org/profile/v1",
      env: "PROFILE_SERVER",
      arg: "profile-server",
    },
    clientId: {
      doc: "The OAuth client ID",
      format: String,
      default: "",
      env: "CLIENT_ID",
      arg: "client-id"
    },
    clientSecret: {
      doc: "The OAuth client secret",
      format: String,
      default: "",
      env: "CLIENT_SECRET",
      arg: "client-secret"
    }
  },
  db: {
    user: {
      doc: "The Postgres user",
      format: String,
      default: process.env.USER,
      env: "RDS_USERNAME",
      arg: "db-user"
    },
    password: {
      doc: "The Postgres password",
      format: String,
      default: "",
      env: "RDS_PASSWORD",
      arg: "db-pass"
    },
    host: {
      doc: "The Postgres server host and port",
      format: String,
      default: "localhost:5432",
      env: "RDS_HOSTNAME",
      arg: "db-host"
    },
    dbname: {
      doc: "The Postgres database",
      format: String,
      default: "",
      env: "RDS_NAME",
      arg: "db-name"
    }
  },
  productName: {
    doc: "Override the 'PageShot' product name",
    format: String,
    default: "PageShot",
    env: "PRODUCT_NAME",
    arg: "product-name"
  },
  gaId: {
    doc: "Give the Google Analytics code",
    format: String,
    default: "",
    env: "GA_ID",
    arg: "ga-id"
  },
  exportBase: {
    doc: "File location to keep exports",
    format: String,
    default: path.join(path.dirname(__dirname), "export-files"),
    env: "EXPORT_BASE",
    arg: "export-base"
  },
  exportKeepTime: {
    doc: "Minutes to keep an export",
    format: "int",
    default: 60,
    env: "EXPORT_KEEP_TIME",
    arg: "export-keep-time"
  },
  // This is mostly configurable for debugging purposes:
  checkDeletedInterval: {
    doc: "Frequency in seconds to check for items that should be purged",
    format: "int",
    default: 60,
    env: "CHECK_DELETED_INTERVAL",
    arg: "check-deleted-interval"
  },
  expiredRetentionTime: {
    doc: "Amount of time to keep an expired shot, in seconds",
    format: "int",
    default: 60*60*24*14, // 14 days
    env: "EXPIRED_RETENTION_TIME",
    arg: "expired-retention-time"
  },
  defaultExpiration: {
    doc: "Default expiration time, in seconds",
    format: "int",
    default: 60*60*24*14, // 14 days
    env: "DEFAULT_EXPIRATION",
    arg: "default-expiration"
  },
  allowExport: {
    doc: "Whether to allow exporting shots",
    format: Boolean,
    default: false,
    env: "ALLOW_EXPORT",
    arg: "allow-export"
  },
  sentryDSN: {
    doc: "The sentry DSN URL to use for recording errors, if any. Sentry is not used on the server unless this parameter is provided.",
    format: String,
    default: "",
    env: "SENTRY_DSN",
    arg: "sentry-dsn"
  },
  sentryPublicDSN: {
    doc: "The public sentry DSN URL to use for recording errors from the site and from the addon. Sentry is not used on the client if this parameter is not provided.",
    format: String,
    default: "",
    env: "SENTRY_PUBLIC_DSN",
    arg: "sentry-public-dsn"
  },
  upgradeSearchBatchSize: {
    doc: "Number of search records to try to upgrade at one time (in minutes)",
    format: "int",
    default: 100,
    env: "UPGRADE_SEARCH_BATCH_SIZE",
    arg: "upgrade-search-batch-size"
  },
  log: {
    lint: {
      doc: "Whether to lint usage of log messages",
      format: Boolean,
      default: false,
      env: "LOG_LINT",
      arg: "log-lint"
    },
    level: {
      doc: "Log level to emit",
      format: String,
      default: "info",
      env: "LOG_LEVEL",
      arg: "log-level"
    }
  },
  showStackTraces: {
    doc: "Whether to show stack traces in 500 HTTP responses",
    format: Boolean,
    default: false,
    env: "SHOW_STACK_TRACES",
    arg: "show-stack-traces"
  }
});

conf.validate({ strict: true });

module.exports = conf;

@@ -3230,173 +3230,8 @@
  %7D,%0A
-  productName: %7B%0A    doc: %22Override the 'PageShot' product name%22,%0A    format: String,%0A    default: %22PageShot%22,%0A    env: %22PRODUCT_NAME%22,%0A    arg: %22product-name%22%0A  %7D,%0A
   ga

Remove unused productName configuration