import * as _ from "lodash"; import { AppConfigType } from '../common/entities/AppConfig'; export class SimplySmartService { private readonly outcodes: Set; constructor(private APP_CONFIG: any, private appConfig: AppConfigType, private localStorageService: any, private experimentService: any, private RUNNING_EXPERIMENTS: any, private eligibilityService: any) { this.outcodes = new Set(["B1", "B10", "B11", "B12", "B13", "B14", "B15", "B16", "B17", "B18", "B19", "B2", "B20", "B21", "B24", "B25", "B26", "B27", "B28", "B29", "B3", "B30", "B32", "B33", "B34", "B35", "B36", "B38", "B4", "B40", "B42", "B43", "B45", "B46", "B47", "B48", "B49", "B5", "B50", "B6", "B60", "B61", "B62", "B63", "B64", "B65", "B66", "B67", "B68", "B69", "B7", "B70", "B71", "B72", "B73", "B74", "B75", "B76", "B78", "B8", "B80", "B9", "B90", "B91", "B92", "B93", "B94", "B95", "B96", "B97", "B98", "BB1", "BB10", "BB11", "BB12", "BB18", "BB2", "BB3", "BB4", "BB5", "BB6", "BB7", "BB8", "BB9", "BD24", "BL0", "BL11", "BL2", "BL3", "BL4", "BL5", "BL6", "BL7", "BL8", "BL9", "CB1", "CB10", "CB11", "CB2", "CB21", "CB22", "CB23", "CB24", "CB25", "CB3", "CB4", "CB5", "CB7", "CB8", "CB9", "CH1", "CH2", "CH3", "CH41", "CH42", "CH43", "CH44", "CH45", "CH46", "CH47", "CH48", "CH49", "CH60", "CH61", "CH62", "CH63", "CH64", "CH66", "CM0", "CM2", "CM3", "CM7", "CM77", "CM8", "CM9", "CO1", "CO11", "CO12", "CO13", "CO14", "CO15", "CO16", "CO2", "CO3", "CO4", "CO5", "CO6", "CO7", "CV1", "CV11", "CV12", "CV13", "CV2", "CV21", "CV22", "CV23", "CV3", "CV31", "CV32", "CV33", "CV34", "CV35", "CV36", "CV37", "CV4", "CV47", "CV5", "CV6", "CV7", "CV8", "CV9", "CW1", "CW10", "CW11", "CW2", "CW3", "CW4", "CW6", "CW7", "CW8", "CW9", "DE1", "DE12", "DE13", "DE14", "DE15", "DE21", "DE22", "DE3", "DE4", "DE45", "DE5", "DE55", "DE56", "DE6", "DE65", "DE7", "DE72", "DE73", "DE74", "DE75", "DE99", "DY1", "DY10", "DY11", "DY12", "DY13", "DY14", "DY2", "DY3", "DY4", "DY5", "DY6", "DY7", "DY8", "DY9", "FY2", "FY5", "FY6", "FY7", "FY8", "GL10", "GL16", "GL17", "GL18", "GL19", "GL53", "GL55", "GL56", "HP19", "HP20", "HP21", "HP22", "HP23", "HR1", "HR5", "HR7", "HR8", "IP10", "IP11", "IP13", "IP14", "IP15", "IP16", "IP17", "IP18", "IP19", "IP2", "IP20", "IP21", "IP22", "IP23", "IP24", "IP25", "IP26", "IP27", "IP28", "IP29", "IP3", "IP30", "IP31", "IP32", "IP33", "IP4", "IP5", "IP6", "IP7", "IP8", "IP9", "L1", "L10", "L11", "L12", "L13", "L14", "L15", "L16", "L17", "L18", "L19", "L2", "L20", "L21", "L22", "L23", "L24", "L25", "L26", "L27", "L28", "L29", "L3", "L30", "L31", "L32", "L33", "L34", "L35", "L37", "L38", "L39", "L40", "L5", "L6", "L7", "L8", "L9", "LA11", "LA15", "LA16", "LA17", "LA18", "LA2", "LA20", "LA3", "LA5", "LA6", "LA7", "LE1", "LE13", "LE14", "LE16", "LE17", "LE19", "LE2", "LE3", "LE4", "LE5", "LE55", "LE6", "LE65", "LE7", "LE8", "LE87", "LE9", "LE95", "LU1", "LU4", "LU5", "LU6", "LU7", "M1", "M11", "M12", "M13", "M14", "M15", "M16", "M17", "M18", "M19", "M2", "M20", "M21", "M23", "M24", "M25", "M26", "M27", "M28", "M29", "M3", "M30", "M31", "M32", "M33", "M34", "M35", "M38", "M4", "M41", "M43", "M44", "M45", "M46", "M5", "M50", "M60", "M7", "M8", "M90", "MK1", "MK10", "MK11", "MK12", "MK13", "MK14", "MK15", "MK16", "MK17", "MK18", "MK19", "MK2", "MK3", "MK4", "MK40", "MK41", "MK42", "MK43", "MK44", "MK45", "MK46", "MK5", "MK6", "MK7", "MK8", "MK9", "NG1", "NG11", "NG12", "NG13", "NG14", "NG15", "NG16", "NG2", "NG21", "NG25", "NG3", "NG31", "NG32", "NG33", "NG4", "NG80", "NG90", "NN1", "NN10", "NN11", "NN12", "NN13", "NN14", "NN15", "NN16", "NN17", "NN18", "NN2", "NN29", "NN3", "NN4", "NN5", "NN6", "NN7", "NN8", "NN9", "NR1", "NR10", "NR11", "NR12", "NR13", "NR14", "NR15", "NR16", "NR17", "NR18", "NR19", "NR2", "NR20", "NR21", "NR22", "NR23", "NR24", "NR25", "NR26", "NR27", "NR28", "NR29", "NR30", "NR31", "NR33", "NR34", "NR35", "NR4", "NR5", "NR6", "NR7", "NR8", "NR9", "OL1", "OL10", "OL11", "OL12", "OL13", "OL15", "OL16", "OL2", "OL3", "OL4", "OL5", "OL6", "OL7", "OL8", "OL9", "OX1", "OX13", "OX15", "OX17", "OX20", "OX25", "OX27", "OX29", "OX33", "OX39", "OX44", "OX49", "OX9", "PE14", "PE15", "PE16", "PE19", "PE26", "PE27", "PE28", "PE29", "PE31", "PE32", "PE33", "PE34", "PE35", "PE36", "PE37", "PE38", "PE5", "PE8", "PE9", "PR1", "PR2", "PR25", "PR26", "PR3", "PR4", "PR5", "PR6", "PR7", "PR8", "PR9", "RG8", "S45", "SG15", "SG16", "SG17", "SG18", "SG19", "SG3", "SG4", "SG5", "SG6", "SG7", "SG8", "SG9", "SK1", "SK10", "SK11", "SK12", "SK13", "SK14", "SK15", "SK16", "SK17", "SK2", "SK22", "SK23", "SK3", "SK4", "SK5", "SK6", "SK7", "SK8", "SK9", "SN7", "ST1", "ST10", "ST11", "ST12", "ST13", "ST14", "ST15", "ST16", "ST17", "ST18", "ST19", "ST2", "ST20", "ST21", "ST3", "ST4", "ST5", "ST6", "ST7", "ST8", "ST9", "SY12", "SY13", "SY14", "SY6", "SY9", "TF10", "TF11", "TF12", "TF13", "TF5", "TF6", "TF8", "TF9", "WA1", "WA10", "WA11", "WA12", "WA13", "WA14", "WA15", "WA16", "WA2", "WA3", "WA4", "WA5", "WA6", "WN1", "WN2", "WN3", "WN4", "WN5", "WN6", "WN7", "WN8", "WR1", "WR10", "WR12", "WR13", "WR15", "WR2", "WR3", "WR5", "WR6", "WR7", "WR8", "WR9", "WR99", "WS1", "WS10", "WS11", "WS12", "WS13", "WS14", "WS15", "WS2", "WS4", "WS5", "WS6", "WS7", "WS8", "WS9", "WV1", "WV13", "WV14", "WV15", "WV16", "WV4", "WV5", "WV7", "WV8", "WV9"]); } private getOutcode(postcode: string): string | null { if (!_.isString(postcode)) return null; postcode = postcode.replace(/\s+/g, "").toUpperCase(); if (postcode.length >= 5) { return postcode.substr(0, postcode.length - 3); } return null; } shouldForceShowSimplySmart(checkAreaEligibility?: Boolean): boolean { let postcode = this.localStorageService.get("postcode"); let outcode = this.getOutcode(postcode); // If area eligibility check required, skip the direct mail postcode check. if (checkAreaEligibility) { return this.appConfig.retailer === 'OVO' && this.eligibilityService.isAreaEligibleForTariff(); } return this.APP_CONFIG.SIMPLY_SMART_POSTCODE_CHECK && this.appConfig.retailer === 'OVO' && !_.isEmpty(postcode) && !_.isEmpty(outcode) && this.outcodes.has(outcode); } shouldShowSimplySmart(): boolean { return this.eligibilityService.isAreaEligibleForTariff() && this.experimentService.activateAndGetStatus(this.RUNNING_EXPERIMENTS.SIMPLY_SMART) } }