const SERVICE_ENV_KEYS = Object.freeze({
  AISFOR: 'AISFOR_CHAIN_KEY_AISFOR',
  AISTALK: 'AISFOR_CHAIN_KEY_AISTALK',
  AISGROUP: 'AISFOR_CHAIN_KEY_AISGROUP',
  AISMALL: 'AISFOR_CHAIN_KEY_AISMALL',
  PLAISHARING: 'AISFOR_CHAIN_KEY_PLAISHARING',
  DONATION: 'AISFOR_CHAIN_KEY_DONATION',
  SUN: 'AISFOR_CHAIN_KEY_SUN'
});

function isAuthRequired() {
  return process.env.AISFOR_CHAIN_AUTH_REQUIRED === '1';
}

function getServiceSecret(serviceName) {
  const key = SERVICE_ENV_KEYS[String(serviceName || '').trim().toUpperCase()];
  return key ? String(process.env[key] || '').trim() : '';
}

function getConfiguredServices() {
  return Object.keys(SERVICE_ENV_KEYS).filter((serviceName) => Boolean(getServiceSecret(serviceName)));
}

module.exports = {
  SERVICE_ENV_KEYS,
  getConfiguredServices,
  getServiceSecret,
  isAuthRequired
};
