import dotenv from "dotenv";
import { logFatal } from "./logger";

dotenv.config();

const GetString = (key: string): string => {
  const val = process.env[key];
  if (val === undefined) {
    logFatal(`Missing ENV: ${key}. This is required to spawn the app.`);
    return "";
  }
  return val;
};

const GetInt = (key: string): number => {
  const val = process.env[key];
  if (val === undefined) {
    logFatal(`Missing ENV: ${key}. This is required to spawn the app.`);
    return 0;
  }
  return Number.parseInt(val);
};

const GetBool = (key: string): boolean => {
  const val = process.env[key];
  if (val === undefined) {
    logFatal(`Missing ENV: ${key}. This is required to spawn the app.`);
    return false;
  }
  return Boolean(val);
};

export const env = {
  GetString,
  GetBool,
  GetInt,
};
