3030import org .signal .registration .analytics .AttemptPendingAnalysis ;
3131import org .signal .registration .analytics .AttemptPendingAnalysisRepository ;
3232import org .signal .registration .analytics .Money ;
33- import org .signal .registration .cli .bigtable .BigtableInfobipDefaultSmsPricesRepository ;
3433import org .signal .registration .metrics .MetricsUtil ;
3534import org .signal .registration .sender .infobip .classic .InfobipSmsSender ;
3635import org .slf4j .Logger ;
3736import org .slf4j .LoggerFactory ;
3837import reactor .core .publisher .Flux ;
3938import reactor .core .publisher .Mono ;
40- import reactor .core .scheduler .Schedulers ;
4139import reactor .util .retry .Retry ;
4240
4341@ Singleton
@@ -47,10 +45,10 @@ class InfobipSmsAttemptAnalyzer {
4745 private final Clock clock ;
4846
4947 private final SmsApi infobipSmsApiClient ;
50- private final BigtableInfobipDefaultSmsPricesRepository defaultSmsPricesRepository ;
51- private final Currency defaultPriceCurrency ;
48+ private final InfobipSmsPriceEstimator infobipSmsPriceEstimator ;
5249 private final MeterRegistry meterRegistry ;
5350 private final int pageSize ;
51+
5452 private static final Logger logger = LoggerFactory .getLogger (InfobipSmsAttemptAnalyzer .class );
5553 private static final int MIN_MCC_MNC_LENGTH = 5 ;
5654 private static final int MAX_RETRIES = 10 ;
@@ -64,17 +62,15 @@ protected InfobipSmsAttemptAnalyzer(
6462 final ApplicationEventPublisher <AttemptAnalyzedEvent > attemptAnalyzedEventPublisher ,
6563 final Clock clock ,
6664 final SmsApi infobipSmsApiClient ,
67- final BigtableInfobipDefaultSmsPricesRepository defaultSmsPricesRepository ,
68- @ Value ("${analytics.infobip.sms.default-price-currency:USD}" ) final String defaultPriceCurrency ,
65+ final InfobipSmsPriceEstimator infobipSmsPriceEstimator ,
6966 final MeterRegistry meterRegistry ,
7067 @ Value ("${analytics.infobip.sms.page-size}" ) final int pageSize ) {
7168
7269 this .repository = repository ;
7370 this .attemptAnalyzedEventPublisher = attemptAnalyzedEventPublisher ;
7471 this .clock = clock ;
7572 this .infobipSmsApiClient = infobipSmsApiClient ;
76- this .defaultSmsPricesRepository = defaultSmsPricesRepository ;
77- this .defaultPriceCurrency = Currency .getInstance (defaultPriceCurrency );
73+ this .infobipSmsPriceEstimator = infobipSmsPriceEstimator ;
7874 this .meterRegistry = meterRegistry ;
7975 this .pageSize = pageSize ;
8076 }
@@ -94,17 +90,16 @@ protected void analyzeAttempts() {
9490 if (smsLogsByRemoteId .containsKey (attemptPendingAnalysis .getRemoteId ())) {
9591 final SmsLog smsLog = smsLogsByRemoteId .get (attemptPendingAnalysis .getRemoteId ());
9692 final MccMnc mccMnc = MccMnc .fromString (smsLog .getMccMnc ());
97- final Optional <Money > maybeEstimatedPriceByMccMnc = estimatePrice (mccMnc .toString ());
9893
9994 attemptAnalysis = new AttemptAnalysis (
10095 extractPrice (smsLog ),
101- maybeEstimatedPriceByMccMnc . or (() -> estimatePrice (attemptPendingAnalysis . getRegion () )),
96+ infobipSmsPriceEstimator . estimatePrice (attemptPendingAnalysis , mccMnc . mcc (), mccMnc . mnc ( )),
10297 Optional .ofNullable (mccMnc .mcc ),
10398 Optional .ofNullable (mccMnc .mnc ));
10499 } else {
105100 attemptAnalysis = new AttemptAnalysis (
106101 Optional .empty (),
107- estimatePrice (attemptPendingAnalysis . getRegion () ),
102+ infobipSmsPriceEstimator . estimatePrice (attemptPendingAnalysis , null , null ),
108103 Optional .empty (),
109104 Optional .empty ());
110105 }
@@ -161,11 +156,6 @@ private Optional<Money> extractPrice(final SmsLog smsLog) {
161156 : Optional .empty ();
162157 }
163158
164- private Optional <Money > estimatePrice (final String key ) {
165- return defaultSmsPricesRepository .get (key )
166- .map (price -> new Money (price , defaultPriceCurrency ));
167- }
168-
169159 @ VisibleForTesting
170160 record MccMnc (String mcc , String mnc ) {
171161 private static final MccMnc EMPTY = new MccMnc (null , null );
@@ -184,9 +174,5 @@ static MccMnc fromString(@Nullable final String mccMnc) {
184174 // Mobile country code is always 3 digits: https://en.wikipedia.org/wiki/Mobile_country_code
185175 return new MccMnc (mccMnc .substring (0 , 3 ), mccMnc .substring (3 ));
186176 }
187-
188- public String toString () {
189- return mcc + mnc ;
190- }
191177 }
192178}
0 commit comments