import { find } from "lodash"; export class BoltOnService { constructor( private quoteState: any, private $stateParams: ng.ui.IStateParamsService, private userDataState: any, private SERVICE_TYPES: any ) {} // Ultimately this will have some logic behind it but I'm really just creating // this service as a placeholder to keep this logic out of the controller. getBoltOnsForTariff(tariffId: string): Array { let boltOns: BoltOn[] = []; if (tariffId === 'Fixed') { let quote = this.quoteState.get(); let supply = quote.supplies[this.$stateParams['supplyId']]; let tariff: any = find(supply, (tariff: any) => tariff.id === tariffId); let greenTariff: any = find(supply, (tariff: any) => tariff.id === 'Green'); let serviceType = this.userDataState.serviceType === this.SERVICE_TYPES.FULL_SERVICE ? 1 : 0; // Cost is, for now, the difference between the tariff and the green tariff. let cost: number = greenTariff.tariffs[serviceType].estimatedMonthlySpend - tariff.tariffs[serviceType].estimatedMonthlySpend; let greenBoltOn: BoltOn = { id: 'green', name: '100% Green electricity', cost, benefits: [ { title: '100% green electricity from renewable sources like hydro, solar and wind.' }, { title: 'PLUS We\'ll plant 5 trees for you to help offset harmful carbon emissions.', disclaimerText: 'We provide an environmental benefit on our Greener tariff by planting trees across the UK. From April 2016 - March 2017 we are aiming to plant 250,000 trees (approximately 5 per Greener tariff customer). Our Better and Simpler tariffs do not contain an environmental benefit.', disclaimerSymbol: '**' } ], icons: { default: '/img/boltons/green-default.svg', selected: '/img/boltons/green-selected.svg', basket: '/img/boltons/green-basket.svg' } } boltOns.push(greenBoltOn); } return boltOns; } } export interface BoltOn { id: string; name: string; cost: number; benefits: Array icons: BoltonIcons; } export interface BoltonIcons { default: string; selected: string; basket: string; } export interface BoltOnBenefit { title: string; disclaimerText?: string; disclaimerSymbol?: string; }