import { Mode, Retailer } from '../entities/Enums'; export class HostExtractor { readonly mode: Mode; readonly isAgentMode: boolean; readonly retailer: Retailer; constructor($location: ng.ILocationService) { const hostRegex = /^.*(switch|movein)(-csa)?(-\w+)?\.(.*)$/; try { const [/*ignore*/, mode, csa, /*ignore*/, site] = $location.host().match(hostRegex); this.mode = this.getMode(mode); this.isAgentMode = !!csa; this.retailer = this.getRetailer(site); } catch (e) { console.warn("Host URL malformed. Make sure you are accessing the site via a 'switch-xyz' route") } } private getMode(mode: string): Mode { switch (mode) { case 'switch': return 'Switch'; case 'movein': return 'MoveIn'; } } private getRetailer(site: string): Retailer { switch (site) { case 'ovoenergy.com': return 'OVO'; case 'fairerpower.co.uk': return 'Fairerpower'; case 'peterboroughenergy.co.uk': return 'PeterboroughEnergy'; case 'southendenergy.co.uk': return 'SouthendEnergy'; case 'energysw.co.uk': return 'EnergySW'; } } }