const fs = require('node:fs');
const path = require('node:path');
const BRANDS = Object.freeze({
  transferwing: Object.freeze({ id: 'transferwing', name: 'TransferWing', appId: 'com.transferwing.desktop', serviceOrigin: 'https://t.mailtingpot.com' }),
  relyo: Object.freeze({ id: 'relyo', name: 'Relyo', appId: 'online.relyo.desktop', serviceOrigin: 'https://relyo.online' }),
});
function readBrand(root = path.join(__dirname, '..')) {
  let config;
  try { config = JSON.parse(fs.readFileSync(path.join(root, 'build-brand.json'), 'utf8')); }
  catch (error) { if(error.code === 'ENOENT') return BRANDS.transferwing; throw new Error('Configuration de marque invalide.'); }
  if(!config || Array.isArray(config) || Object.keys(config).length !== 1 || !Object.hasOwn(BRANDS, config.id)) throw new Error('Configuration de marque invalide.');
  return BRANDS[config.id];
}
function brandPaths(appData, brand) {
  // macOS safeStorage keys differ between the signed application identities.
  // Never overwrite another brand's encrypted activation file.
  const userData = path.join(appData, brand.id === 'relyo' ? 'Relyo' : 'relio-local');
  return { licenseDirectory: userData, userData };
}
module.exports = { BRANDS, readBrand, brandPaths };
