const dotenv = require('dotenv');
dotenv.config();

const parseString = (key) => {
  const value = process.env[key];
  if (!value) {
    throw new Error(`${key} is not present`);
  }
  return value;
};

const parseNumber = (key) => {
  const value = process.env[key];
  if (!value) {
    throw new Error(`${key} is not present`);
  }
  const parsed = parseInt(value, 10);
  if (isNaN(parsed)) {
    throw new Error(`${key} should be a number`);
  }
  return parsed;
};

const parseBoolean = (key) => {
  const value = process.env[key];
  if (!value) {
    throw new Error(`${key} is not present`);
  }
  if (value === 'TRUE' || value === 'true') {
    return true;
  } else if (value === 'FALSE' || value === 'false') {
    return false;
  }
  throw new Error(`${key} should be TRUE or true or FALSE or false`);
};

module.exports = {
  // SERVER_URL: parseString('SERVER_URL'),
  GITHUB_TOKEN: parseString('GITHUB_TOKEN'),
  DEEP_LINKING_URL: parseString('DEEP_LINKING_URL'),
  CERTIFICATE_PASSWORD: parseString('CERTIFICATE_PASSWORD'),
};
