{"version":3,"file":"index-DlKQKdU4.js","sources":["../../Client/business/CommonSets/RatingType/index.ts"],"sourcesContent":["type SwitchFunctions<T> = {\r\n    onAdmitted: () => T;\r\n    onEAndS: () => T;\r\n    onNfip: () => T;\r\n};\r\n\r\nexport class RatingType {\r\n    readonly id: number;\r\n    readonly abbreviation: string;\r\n    readonly value: string;\r\n    readonly displayValue: string;\r\n\r\n    private constructor(id: number, abbreviation: string, value: string, displayValue?: string) {\r\n        this.id = id;\r\n        this.value = value;\r\n        this.abbreviation = abbreviation;\r\n        this.displayValue = displayValue || value;\r\n    }\r\n\r\n    /** Admitted business (i.e. not excess and surplus insurance). */\r\n    public static readonly Admitted = new RatingType(1, 'AD', 'Admitted');\r\n\r\n    /** Excess and surplus lines insurance. */\r\n    public static readonly EAndS = new RatingType(2, 'ES', 'EAndS', 'E&S');\r\n\r\n    /** A RatingType that is near impossible to be used with a Quote. Primarily used as a second excel rater and needed for seeding data.\r\n     * There are no quotes in any database (prod, beta, dev) with this RatingType. This is here because it exists but will likely never be used.\r\n     */\r\n    public static readonly Adequacy = new RatingType(3, 'RA', 'Adequacy');\r\n\r\n    /** NFIP is neither admitted nor E&S because it is US government insurance. */\r\n    public static readonly Nfip = new RatingType(4, 'NF', 'NFIP');\r\n\r\n    public switch<T>({ onAdmitted, onEAndS, onNfip }: SwitchFunctions<T>): T {\r\n        switch (this) {\r\n            case RatingType.Admitted:\r\n                return onAdmitted();\r\n            case RatingType.EAndS:\r\n                return onEAndS();\r\n            case RatingType.Nfip:\r\n                return onNfip();\r\n            default:\r\n                throw new Error(`RatingType case not implemented: ${this}`);\r\n        }\r\n    }\r\n}\r\n\r\nexport namespace RatingType {\r\n    export function all(): RatingType[] {\r\n        return [RatingType.Admitted, RatingType.EAndS, RatingType.Nfip];\r\n    }\r\n\r\n    export function parseOrDefault(value: string | number | undefined | null): RatingType | null {\r\n        return (\r\n            all().find(ratingType => {\r\n                if (typeof value === 'number') return ratingType.id === value;\r\n                return stringMatchesProperty(ratingType);\r\n            }) || null\r\n        );\r\n\r\n        function stringMatchesProperty(ratingType: RatingType) {\r\n            if (typeof value !== 'string') return false;\r\n\r\n            const properties = [\r\n                    ratingType.id.toString(),\r\n                    ratingType.value,\r\n                    ratingType.abbreviation,\r\n                    ratingType.displayValue,\r\n                ],\r\n                normalizedValue = value.toLowerCase();\r\n\r\n            return properties.some(matcher => matcher.toLowerCase() === normalizedValue);\r\n        }\r\n    }\r\n\r\n    export function parse(value: string | number | undefined | null): RatingType {\r\n        const result = parseOrDefault(value);\r\n        if (!result) {\r\n            throw new Error(`Could not parse any RatingType from the value: ${value}`);\r\n        }\r\n\r\n        return result;\r\n    }\r\n}\r\n"],"names":["_RatingType","id","abbreviation","value","displayValue","__publicField","onAdmitted","onEAndS","onNfip","RatingType","all","parseOrDefault","ratingType","stringMatchesProperty","properties","normalizedValue","matcher","parse","result"],"mappings":"oKAMO,MAAMA,EAAN,MAAMA,CAAW,CAMZ,YAAYC,EAAYC,EAAsBC,EAAeC,EAAuB,CALnFC,EAAA,WACAA,EAAA,qBACAA,EAAA,cACAA,EAAA,qBAGL,KAAK,GAAKJ,EACV,KAAK,MAAQE,EACb,KAAK,aAAeD,EACpB,KAAK,aAAeE,GAAgBD,CAAA,CAiBjC,OAAU,CAAE,WAAAG,EAAY,QAAAC,EAAS,OAAAC,GAAiC,CACrE,OAAQ,KAAM,CACV,KAAKR,EAAW,SACZ,OAAOM,EAAW,EACtB,KAAKN,EAAW,MACZ,OAAOO,EAAQ,EACnB,KAAKP,EAAW,KACZ,OAAOQ,EAAO,EAClB,QACI,MAAM,IAAI,MAAM,oCAAoC,IAAI,EAAE,CAAA,CAClE,CAER,EAzBIH,EAdSL,EAcc,WAAW,IAAIA,EAAW,EAAG,KAAM,UAAU,GAGpEK,EAjBSL,EAiBc,QAAQ,IAAIA,EAAW,EAAG,KAAM,QAAS,KAAK,GAKrEK,EAtBSL,EAsBc,WAAW,IAAIA,EAAW,EAAG,KAAM,UAAU,GAGpEK,E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