const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');

const envPath = path.join(__dirname, '../.env');
const examplePath = path.join(__dirname, '../.env.example');
if (!fs.existsSync(envPath) && fs.existsSync(examplePath)) {
  fs.copyFileSync(examplePath, envPath);
}
dotenv.config({ path: envPath });

module.exports = {
  port: Number(process.env.PORT || 8080),
  db: {
    host: process.env.DB_HOST || 'localhost',
    port: Number(process.env.DB_PORT || 3306),
    user: process.env.DB_USER || 'root',
    password: process.env.DB_PASS || '',
    database: process.env.DB_NAME || 'vts_v2',
  },
  otpDebug: process.env.OTP_DEBUG === 'true',
  offlineAfterSeconds: Number(process.env.OFFLINE_AFTER_SECONDS || 300),
};
