/// <summary>
        /// Request token for (InitToken for Unregistered/Registered customer)
        /// </summary>
        /// <param name="communityId"></param>
        /// <param name="customerId"></param>
        /// <returns></returns>
        public async Task <ApiResponse> RequestToken(DealerCDKConfiguration dealerCDKConfig, string communityId, string customerId = null)
        {
            if (communityId == null)
            {
                throw new ArgumentNullException(nameof(communityId));
            }
            if (string.IsNullOrWhiteSpace(customerId))
            {
                customerId = _unregisteredGuid;
            }

            var requestBody = UtilityHelper.SerializeObject(new
            {
                CustomerId = customerId,
                dealerCDKConfig.PartnerId,
                Version = dealerCDKConfig.PartnerVersion
            });
            var request = new ApiRequest
            {
                Body        = requestBody,
                Method      = HttpVerbs.POST.ToString(),
                Url         = CombineUrl(GetCdkAutolineUrl(_cdkAutolineUrl, communityId), RequestTokenUrl),
                ContentType = Constants.ContentTypeJson
            };

            return(await _restApiClient.Invoke <TokenResponse>(request));
        }
        internal async Task <string> RequestAndActivateAppToken(DealerCDKConfiguration dealerCDKConfig, string communityId, AppToken appToken, bool isTokenFetchedFromDb)
        {
            string token;

            if (!isTokenFetchedFromDb)
            {
                var requestApiResponse = await RequestToken(dealerCDKConfig, communityId);

                if (requestApiResponse.Result == null || !requestApiResponse.Success || !(requestApiResponse.Result is TokenResponse objRequestToken))
                {
                    var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(requestApiResponse.Errors));
                    _telemetryClient?.TrackException(cdkAutolineException);
                    throw cdkAutolineException;
                }

                token = objRequestToken.Token;
            }
            else
            {
                token = appToken.Token.ToString();
            }

            //Activate Token from generated token.
            var activeApiTokenResponse = await ActivateToken(communityId, token, dealerCDKConfig.PartnerKey);

            if (activeApiTokenResponse == null || !activeApiTokenResponse.Success)
            {
                if (isTokenFetchedFromDb)
                {
                    return(null);
                }

                var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(activeApiTokenResponse?.Errors));
                _telemetryClient?.TrackException(cdkAutolineException);
                throw cdkAutolineException;
            }

            return(token);
        }
        internal async Task <string> RequestAndActivateCustomerToken(CdkCustomer cdkCustomer, DealerCDKConfiguration dealerCDKConfig, string roofTopId, Guid?existingToken)
        {
            if (existingToken == null)
            {
                var requestApiResponse = await RequestToken(dealerCDKConfig, cdkCustomer.CommunityId, cdkCustomer.CustomerLoginId);

                if (requestApiResponse.Result == null || !requestApiResponse.Success ||
                    !(requestApiResponse.Result is TokenResponse objRequestToken) ||
                    string.IsNullOrWhiteSpace(objRequestToken.Token))
                {
                    var cdkAutolineException = new CDKAutolineException(UtilityHelper.SerializeObject(requestApiResponse.Errors));
                    _telemetryClient?.TrackException(cdkAutolineException);
                    throw cdkAutolineException;
                }

                cdkCustomer.Token = new Guid(objRequestToken.Token);
            }

            //Activate Token from generated token.
            var checkPasswordApiResponse = await _customerService.CheckPassword(new CustomerVerifyRequest
            {
                CommunityId = cdkCustomer.CommunityId,
                CustomerNo  = cdkCustomer.CustomerNo,
                RoofTopId   = roofTopId
            }, cdkCustomer, dealerCDKConfig.PartnerKey);

            if (checkPasswordApiResponse == null || !checkPasswordApiResponse.Success)
            {
                if (existingToken != null)
                {
                    return(null);
                }
                throw new CDKAutolineException(UtilityHelper.SerializeObject(checkPasswordApiResponse?.Errors));
            }

            await _cdkCustomerService.SaveCdkCustomer(cdkCustomer);

            return(cdkCustomer.Token.ToString());
        }