private fun getRecommendationDetails(token: AddressCleanser) { val headers = HashMap<String, String>() headers["Authorization"] = "Bearer " + token.accessToken val parameters = JsonObject() parameters.add("outputFields", addressCleanseOutputFields()) parameters.add("addressInput", addressCleanseInputFields()) viewModelScope.launch(Dispatchers.IO) { when(val result = getCountryDataUseCase.getRecommendationDetails( headers = headers, body = parameters )) { is RemoteResponse.Success -> { if (result.value.stdAddrAddressDelivery.isEmpty() || result.value.stdAddrLocalityFull.isEmpty() || result.value.stdAddrRegionCode.isEmpty() ) { _uiState.value = uiState.value.copy( dotPagerList = listOf( Dot(completed = true), Dot(completed = true), Dot(), Dot() ), signInProcessing = false ) viewModelScope.launch(Dispatchers.Main) { navigationEvent.emit(RegistrationNavigationEvent.OpenAccountInformationScreen) } } else { _uiState.value = uiState.value.copy( recommendedAddress = RegistrationAddressFields( address1 = InputWrapper(value = result.value.stdAddrAddressDelivery), city = InputWrapper(value = result.value.stdAddrLocalityFull), zipcode = InputWrapper( value = result.value.stdAddrPostcodeFull.split( "-".toRegex() ).map { it.trim() }[0] ), selectedState = InputWrapper(value = result.value.stdAddrRegionFull), selectedCountry = InputWrapper(value = result.value.stdAddrCountry2char) ), signInProcessing = false ) navigateToNextScreen(RegistrationScreenType.RecommendationScreen()) } } is RemoteResponse.Failure -> { } } } }
Function to get the Recommendation details for the address entered by the user