{"version":3,"file":"chunk-h5a6hxj7.js","sources":["packages/sports/web/app/src/crm-promotion-container/crm-promotion-mapper.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { GameType } from '@bpos/v1/sports-promo';\nimport { EventModel, EventOptionGroup } from '@frontend/sports/betting-offer/feature/model';\nimport { hasValue } from '@frontend/sports/common/core/utils/extended-types';\nimport { flatten, keyBy, uniq } from 'lodash-es';\n\nimport { Promotion } from '../crm-offer-data/crm-offer.model';\n\n@Injectable({ providedIn: 'root' })\nexport class CrmPromotionMapperService {\n getBySport(promotions: Promotion[], sportId: number): Promotion[] {\n return promotions.filter((p) => p.banner && p.allFilters.some((f) => f.sportIds.some((spId) => spId === sportId)));\n }\n\n getByCompetition(promotions: Promotion[], competitionIds: number[]): Promotion[] {\n const competitions = keyBy(competitionIds);\n\n return promotions.filter((p) => p.banner && p.allFilters.some((f) => f.competitionIds.some((id) => !!competitions[id])));\n }\n\n getPromotionsForEvent(event: EventModel, promotions: Promotion[]): Promotion[] {\n return promotions.filter((p) => this.isGameType(event.live, p));\n }\n\n getPromotedOptionGroupIds(\n optionGroups: EventOptionGroup[],\n event: EventModel,\n filteredPromotions: Promotion[],\n ): { [optionGroupId: string]: string } {\n if (!filteredPromotions.length) {\n return {};\n }\n\n const allFilters = flatten(filteredPromotions.map((fp) => fp.allFilters));\n const allMarketTemplateIds = flatten(allFilters.map((af) => af.marketTemplateIds));\n const allMarketIds = flatten(allFilters.map((af) => af.marketIds));\n\n let promotedGroups = optionGroups.filter(\n (group) => !group.groupedMarkets && allMarketTemplateIds.some((templateId) => templateId === group.templateId),\n );\n const promotedGroupsByMarket = flatten(allMarketIds.map((marketId) => event.marketsDictionary[marketId]));\n\n promotedGroups = promotedGroups.concat(promotedGroupsByMarket).filter(hasValue);\n const promotedGroupIds = uniq(promotedGroups.map((g) => g.id));\n\n return keyBy(promotedGroupIds);\n }\n\n getBannerPromotions(optionGroups: EventOptionGroup[], event: EventModel, filteredPromotions: Promotion[]): Promotion[] {\n if (!filteredPromotions.length) {\n return [];\n }\n\n const eventTemplateGroupsDictionary = keyBy(optionGroups, (g) => g.templateId);\n const optionsDictionary = keyBy(flatten(optionGroups.map((og) => og.options)), (g) => g.id);\n\n return filteredPromotions.filter((filteredPromo) => {\n if (!filteredPromo.banner) {\n return false;\n }\n\n const hasPromo = filteredPromo.allFilters.some((f) => {\n const fixturePromo = f.fixtureIds.some((fId) => fId === event.id);\n if (fixturePromo) {\n return true;\n }\n\n const templatePromo = f.marketTemplateIds.some((tId) => !!eventTemplateGroupsDictionary[tId]);\n if (templatePromo) {\n return true;\n }\n\n const marketPromo = f.marketIds.some((marketId) => !!event.marketsDictionary[marketId]);\n if (marketPromo) {\n return true;\n }\n\n const optionPromo = f.optionIds.some((optionId) => !!optionsDictionary[optionId]);\n\n return optionPromo;\n });\n\n return hasPromo;\n });\n }\n\n private isGameType(isEventLive: boolean, promotion: Promotion): boolean {\n return (\n promotion.gameType === GameType.Mixed ||\n (isEventLive && promotion.gameType === GameType.InPlay) ||\n (!isEventLive && promotion.gameType === GameType.PreMatch)\n );\n }\n}\n"],"names":["CrmPromotionMapperService","getBySport","promotions","sportId","filter","p","banner","allFilters","some","f","sportIds","spId","getByCompetition","competitionIds","competitions","keyBy","id","getPromotionsForEvent","event","isGameType","live","getPromotedOptionGroupIds","optionGroups","filteredPromotions","length","flatten","map","fp","allMarketTemplateIds","af","marketTemplateIds","allMarketIds","marketIds","promotedGroups","group","groupedMarkets","templateId","promotedGroupsByMarket","marketId","marketsDictionary","concat","hasValue","promotedGroupIds","uniq","g","getBannerPromotions","eventTemplateGroupsDictionary","optionsDictionary","og","options","filteredPromo","fixtureIds","fId","tId","optionIds","optionId","isEventLive","promotion","gameType","factory","ɵfac","providedIn","_CrmPromotionMapperService"],"mappings":"gHAUA,IAAaA,CAAyB,CAAA,CAAA,IAAA,CAAhC,IAAOA,EAAP,MAAOA,CAAyB,CAClCC,UAAAA,CAAWC,CAAyBC,CAAAA,CAAAA,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