export const BRANDS = Object.freeze({
  transferwing: Object.freeze({id:'transferwing',name:'TransferWing',origin:'https://t.mailtingpot.com'}),
  relyo: Object.freeze({id:'relyo',name:'Relyo',origin:'https://relyo.online'}),
});
export function brandForHost(host, fallback='transferwing') {
  if (!Object.hasOwn(BRANDS,fallback)) throw new Error('Unknown local brand');
  return host === 'relyo.online' ? BRANDS.relyo : ['transferwing.com','t.mailtingpot.com'].includes(host) ? BRANDS.transferwing : BRANDS[fallback];
}
// Only first-party static assets are branded; never transform user data or protocol values.
export function brandAsset(data, mime, brand) {
  if (brand.id !== 'relyo' || !/^(text\/html|text\/javascript|image\/svg\+xml)/.test(mime)) return data;
  let content = data.toString('utf8').replaceAll('TransferWing','Relyo').replaceAll('TRANSFERWING','RELYO');
  if (mime.startsWith('text/html')) content = content.replace(/<html\b/, '<html data-brand="relyo"').replace('</head>', '<link rel="stylesheet" href="/relyo-theme.css">\n</head>');
  return Buffer.from(content);
}
