private async Task <UserCreationResult> CheckUsernameAndCreateAsync(string username)
        {
            _httpClient ??= CreateHttpClient();

            string usersServiceUrl = _configuration["ServicesUris:UsersService"];

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri($"{usersServiceUrl}/svc/users?username={username}")
            };

            var response = await _httpClient.SendAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                var errorDto = JsonConvert.DeserializeObject <ErrorResponseDto>(await response.Content.ReadAsStringAsync());
                return(UserCreationResult.Failure(errorDto.Title));
            }


            var userModel = JsonConvert.DeserializeObject <UserModel>(await response.Content.ReadAsStringAsync());

            return(UserCreationResult.Success(userModel.Id));
        }
        public async Task <UserAuthInfo> RegisterAsync(string username, string login, string password)
        {
            if (!(await CheckIsLoginAvailable(login)))
            {
                throw new Exception($"Login {login} already in use");
            }

            UserCreationResult userCreationResult = await CheckUsernameAndCreateAsync(username);

            if (!userCreationResult.IsSuccess)
            {
                throw new Exception(userCreationResult.Error);
            }

            string userId         = userCreationResult.UserId;
            string hashedPassword = _passwordHasher.HashPassword(password);

            return(await _repository.CreateUserInfo(userId, login, hashedPassword));
        }