const DEFAULT_DEV_AUTH_SECRET = "abelbirdnest-dev-secret-change-me";
const DEFAULT_DEV_APP_URL = "http://localhost:3000";

function isProduction() {
  return process.env.NODE_ENV === "production";
}

export function getAuthSecretOrThrow() {
  const value = process.env.AUTH_SECRET?.trim();

  if (value && value !== DEFAULT_DEV_AUTH_SECRET) {
    return value;
  }

  if (isProduction()) {
    throw new Error("AUTH_SECRET wajib diisi dengan secret production yang aman.");
  }

  return value || DEFAULT_DEV_AUTH_SECRET;
}

export function getAppUrlOrThrow() {
  const value = process.env.APP_URL?.trim();

  if (value) {
    return value;
  }

  if (isProduction()) {
    throw new Error("APP_URL wajib diisi di production.");
  }

  return DEFAULT_DEV_APP_URL;
}

export function isAuthBootstrapEnabled() {
  const flag = process.env.AUTH_BOOTSTRAP?.trim().toLowerCase();

  if (flag === "true") return true;
  if (flag === "false") return false;

  return !isProduction();
}
