import * as _ from "lodash"; import { StorageService } from '../services/storage/StorageService'; import { StringMarshaller, LocalDateMarshaller, JSONMarshaller } from '../services/storage/Marshallers'; import { BooleanParser, LocalDateParser, IntParser, JSONParser } from '../services/storage/Parsers'; import { QuoteType, Fuel, PaymentMethod, ServiceType, Usage, Region, UsageUnit, UsagePeriod, Utility, CriticalCode, ServiceOptIn, EnergyUsage, Insulation, TariffId, Title, BundleName, Trinary } from '../entities/Enums'; import { Address } from '../entities/Address'; import { SupplierDetails, SupplierTariff } from '../entities/Suppliers'; import { LocalDate } from 'js-joda'; export class UserDataState { constructor(private cachedStorage: StorageService) { if (!cachedStorage.contains("paymentMethod")) this.paymentMethod = 'Paym'; if (!cachedStorage.contains("fuel")) this.fuel = 'Dual'; if (!cachedStorage.contains("serviceType")) this.serviceType = 'Online'; if (!cachedStorage.contains("usage")) this.usage = 'Medium'; if (!cachedStorage.contains("supplyAddressMutable")) this.supplyAddressMutable = true; if (!cachedStorage.contains("serviceOptIn")) this.serviceOptIn = 'EmailAndSMS'; if (!cachedStorage.contains("foundation")) this.foundation = false; if (!cachedStorage.contains("billToSupplyAddress")) this.billToSupplyAddress = true; if (!cachedStorage.contains("marketingOptIn")) this.marketingOptIn = false; } // Quote parameters get quoteType(): QuoteType { return this.cachedStorage.get("quoteType") } set quoteType(quoteType: QuoteType) { this.cachedStorage.set("quoteType", quoteType) } get fuel(): Fuel { return this.cachedStorage.get("fuel") } set fuel(fuel: Fuel) { this.cachedStorage.set("fuel", fuel) } get paymentMethod(): PaymentMethod { return this.cachedStorage.get("paymentMethod") } set paymentMethod(paymentMethod: PaymentMethod) { this.cachedStorage.set("paymentMethod", paymentMethod) } get postcode(): string { return this.cachedStorage.get("postcode") } set postcode(postcode: string) { this.cachedStorage.set("postcode", postcode) } get region(): Region { return this.cachedStorage.get("region") } set region(region: Region) { this.cachedStorage.set("region", region) } get serviceType(): ServiceType { return this.cachedStorage.get("serviceType") } set serviceType(serviceType: ServiceType) { this.cachedStorage.set("serviceType", serviceType) } get usage(): Usage { return this.cachedStorage.get("usage") } set usage(usage: Usage) { this.cachedStorage.set("usage", usage) } get estimatedUsage(): boolean { return this.cachedStorage.get("estimatedUsage", BooleanParser) } set estimatedUsage(estimatedUsage: boolean) { this.cachedStorage.set("estimatedUsage", estimatedUsage, StringMarshaller) } get economy7(): boolean { return this.cachedStorage.get("economy7", BooleanParser) } set economy7(economy7: boolean) { this.cachedStorage.set("economy7", economy7, StringMarshaller) } get previousGasSupplier(): SupplierDetails { return this.cachedStorage.get("previousGasSupplier", JSONParser) } set previousGasSupplier(previousGasSupplier: SupplierDetails) { this.cachedStorage.set("previousGasSupplier", previousGasSupplier, JSONMarshaller) } get previousGasTariff(): SupplierTariff { return this.cachedStorage.get("previousGasTariff", JSONParser) } set previousGasTariff(previousGasTariff: SupplierTariff) { this.cachedStorage.set("previousGasTariff", previousGasTariff, JSONMarshaller) } get gasUsage(): number { return this.cachedStorage.get("gasUsage", IntParser) } set gasUsage(gasUsage: number) { this.cachedStorage.set("gasUsage", gasUsage, StringMarshaller) } get gasUnit(): UsageUnit { return this.cachedStorage.get("gasUnit") } set gasUnit(gasUnit: UsageUnit) { this.cachedStorage.set("gasUnit", gasUnit) } get gasPeriod(): UsagePeriod { return this.cachedStorage.get("gasPeriod") } set gasPeriod(gasPeriod: UsagePeriod) { this.cachedStorage.set("gasPeriod", gasPeriod) } get previousElectricitySupplier(): SupplierDetails { return this.cachedStorage.get("previousElectricitySupplier", JSONParser) } set previousElectricitySupplier(previousElectricitySupplier: SupplierDetails) { this.cachedStorage.set("previousElectricitySupplier", previousElectricitySupplier, JSONMarshaller) } get previousElectricityTariff(): SupplierTariff { return this.cachedStorage.get("previousElectricityTariff", JSONParser) } set previousElectricityTariff(previousElectricityTariff: SupplierTariff) { this.cachedStorage.set("previousElectricityTariff", previousElectricityTariff, JSONMarshaller) } get electricityUsage(): number { return this.cachedStorage.get("electricityUsage", IntParser) } set electricityUsage(electricityUsage: number) { this.cachedStorage.set("electricityUsage", electricityUsage, StringMarshaller) } get electricityUnit(): UsageUnit { return this.cachedStorage.get("electricityUnit") } set electricityUnit(electricityUnit: UsageUnit) { this.cachedStorage.set("electricityUnit", electricityUnit) } get electricityPeriod(): UsagePeriod { return this.cachedStorage.get("electricityPeriod") } set electricityPeriod(electricityPeriod: UsagePeriod) { this.cachedStorage.set("electricityPeriod", electricityPeriod) } get energyUsage(): EnergyUsage { return this.cachedStorage.get("energyUsage") } set energyUsage(energyUsage: EnergyUsage) { this.cachedStorage.set("energyUsage", energyUsage) } get insulation(): Insulation { return this.cachedStorage.get("insulation") } set insulation(insulation: Insulation) { this.cachedStorage.set("insulation", insulation) } get numberOfOccupants(): number { return this.cachedStorage.get("numberOfOccupants", IntParser) } set numberOfOccupants(numberOfOccupants: number) { this.cachedStorage.set("numberOfOccupants", numberOfOccupants, StringMarshaller) } get numberOfRooms(): number { return this.cachedStorage.get("numberOfRooms", IntParser) } set numberOfRooms(numberOfRooms: number) { this.cachedStorage.set("numberOfRooms", numberOfRooms, StringMarshaller) } // Tariff selections get tariffId(): TariffId { return this.cachedStorage.get("tariffId") } set tariffId(tariffId: TariffId) { this.cachedStorage.set("tariffId", tariffId) } // Eligibility choices get storageHeaters(): Trinary { return this.cachedStorage.get("storageHeaders") } set storageHeaters(storageHeaters: Trinary) { this.cachedStorage.set("storageHeaters", storageHeaters) } get gasBrownBox(): Trinary { return this.cachedStorage.get("gasBrownBox") } set gasBrownBox(gasBrownBox: Trinary) { this.cachedStorage.set("gasBrownBox", gasBrownBox) } get metersDiffFloor(): Trinary { return this.cachedStorage.get("metersDiffFloor") } set metersDiffFloor(metersDiffFloor: Trinary) { this.cachedStorage.set("metersDiffFloor", metersDiffFloor) } get inFlat(): Trinary { return this.cachedStorage.get("inFlat") } set inFlat(inFlat: Trinary) { this.cachedStorage.set("inFlat", inFlat) } // Switch details get title(): Title { return this.cachedStorage.get("title") } set title(title: Title) { this.cachedStorage.set("title", title) } get firstName(): string { return this.cachedStorage.get("firstName") } set firstName(firstName: string) { this.cachedStorage.set("firstName", firstName) } get lastName(): string { return this.cachedStorage.get("lastName") } set lastName(lastName: string) { this.cachedStorage.set("lastName", lastName) } get phone(): string { return this.cachedStorage.get("phone") } set phone(phone: string) { this.cachedStorage.set("phone", phone) } get emailAddress(): string { return this.cachedStorage.get("emailAddress") } set emailAddress(emailAddress: string) { this.cachedStorage.set("emailAddress", emailAddress) } get dateOfBirth(): LocalDate { return this.cachedStorage.get("dateOfBirth", LocalDateParser) } set dateOfBirth(dateOfBirth: LocalDate) { this.cachedStorage.set("dateOfBirth", dateOfBirth, LocalDateMarshaller) } get criticalCode(): CriticalCode { return this.cachedStorage.get<CriticalCode>("criticalCode") } set criticalCode(criticalCode: CriticalCode) { this.cachedStorage.set("criticalCode", criticalCode) } get supplyAddress(): Address { return this.cachedStorage.get<Address>("supplyAddress", JSONParser) } set supplyAddress(supplyAddress: Address) { this.cachedStorage.set("supplyAddress", supplyAddress, JSONMarshaller) } get supplyAddressMutable(): boolean { return this.cachedStorage.get("supplyAddressMutable", BooleanParser) } set supplyAddressMutable(supplyAddressMutable: boolean) { this.cachedStorage.set("supplyAddressMutable", supplyAddressMutable, StringMarshaller) } get billToSupplyAddress(): boolean { return this.cachedStorage.get("billToSupplyAddress", BooleanParser) } set billToSupplyAddress(billToSupplyAddress: boolean) { this.cachedStorage.set("billToSupplyAddress", billToSupplyAddress, StringMarshaller) } get billingAddress(): Address { return this.cachedStorage.get<Address>("billingAddress", JSONParser) } set billingAddress(billingAddress: Address) { this.cachedStorage.set("billingAddress", billingAddress, JSONMarshaller) } get serviceOptIn(): ServiceOptIn { return this.cachedStorage.get<ServiceOptIn>("serviceOptIn") } set serviceOptIn(serviceOptIn: ServiceOptIn) { this.cachedStorage.set("serviceOptIn", serviceOptIn) } get marketingOptIn(): boolean { return false; } set marketingOptIn(marketingOptIn: boolean) { this.cachedStorage.set("marketingOptIn", marketingOptIn, StringMarshaller) } get foundation(): boolean { return this.cachedStorage.get("foundation", BooleanParser) } set foundation(foundation: boolean) { this.cachedStorage.set("foundation", foundation, StringMarshaller) } get moveInDate(): LocalDate { return this.cachedStorage.get("moveInDate", LocalDateParser) } set moveInDate(moveInDate: LocalDate) { this.cachedStorage.set("moveInDate", moveInDate, LocalDateMarshaller) } get bundleName(): BundleName { return this.cachedStorage.get<BundleName>("bundleName") } set bundleName(bundleName: BundleName) { this.cachedStorage.set("bundleName", bundleName) } }