public async Task <ClientWalletEntity> RegisterOrGetDefaultWallets(ClientIdentity client)
        {
            var existWallet = await _walletsWriter.TryGetAsync(ClientWalletEntity.GetPartitionKey(client.TenantId), ClientWalletEntity.GetRowKey(client.ClientId));

            if (existWallet != null)
            {
                return(existWallet);
            }

            bool result;

            do
            {
                var walletId = GenerateWalletId();

                var entity = ClientWalletEntity.Generate(client.TenantId, client.ClientId);
                entity.WalletId = walletId;
                entity.Type     = TradingWalletType.Trading;
                entity.Client   = client;

                var indexById = ClientWalletIndexByIdEntity.Generate(entity.Client.TenantId, walletId, entity.Client.ClientId);
                result = await _walletsByIdWriter.TryInsertAsync(indexById);

                if (result)
                {
                    await _walletsWriter.InsertOrReplaceAsync(entity);

                    return(entity);
                }

                _logger.LogInformation("Cannot insert new wallet with id={WalletId}. ClientId={clientId}, TenantId={TenamtId}", entity.WalletId, entity.Client.TenantId, entity.Client.ClientId);
            } while (true);
        }
        public async Task <RegistrationResult> RegisterClientAsync(
            string tenantId,
            long clientId,
            string requestEmail,
            string requestPassword,
            string requestHint,
            string requestPin)
        {
            var entity = AuthDataEntity.Generate(tenantId, requestEmail);

            entity.ClientId     = clientId;
            entity.Hint         = requestHint;
            entity.Email        = requestEmail;
            entity.PasswordHash = requestPassword.ToBase64();
            entity.PinHash      = requestPin.ToSha256().ToBase64();
            entity.TenantId     = tenantId;

            var insertSuccess = await _dataWriter.TryInsertAsync(entity);

            if (!insertSuccess)
            {
                var exist = await TryGetAuthData(entity.TenantId, entity.Email);

                if (exist != null)
                {
                    return(new RegistrationResult()
                    {
                        IsEmailAlreadyExist = true,
                        IsSuccess = false
                    });
                }
            }

            var indexEntity = AuthDataIndexByIdEntity.Generate(tenantId, clientId, requestEmail);
            await _indexDataWriter.InsertOrReplaceAsync(indexEntity);

            return(new RegistrationResult()
            {
                IsEmailAlreadyExist = false,
                ClientIdentity = new ClientIdentity()
                {
                    ClientId = entity.ClientId,
                    TenantId = entity.TenantId
                },
                IsSuccess = true
            });
        }