public async Task <PaginationResult <UserEntity> > GetUsersAsync(
            ClaimsPrincipal user,
            CancellationToken cancellationToken,
            UserSearchCriteria searchCriteria)
        {
            if (searchCriteria == null)
            {
                throw new ArgumentNullException(nameof(searchCriteria));
            }

            if (!PermissionCheck.HasAdminPermission(user, searchCriteria.TenantId))
            {
                // TODO: Strong-type for authorization exception
                throw new Exception("Access denied");
            }

            var result = await _userStore
                         .GetUsersAsync(searchCriteria, cancellationToken)
                         .ConfigureAwait(false);

            return(new PaginationResult <UserEntity>
            {
                PageIndex = result.PageIndex,
                PageSize = result.PageSize,
                TotalCount = result.TotalCount,
                Items = result.Items.Select(e => new UserEntity(e))
            });
        }
        public async Task <PaginationResult <ClientEntity> > GetClientsAsync(
            ClaimsPrincipal user,
            CancellationToken cancellationToken,
            ClientSearchCriteria clientSearchCriteria)
        {
            if (!user.Identity.IsAuthenticated)
            {
                throw new InvalidOperationException("Missing user context");
            }

            if (!PermissionCheck.HasAdminPermission(user, clientSearchCriteria.TenantId))
            {
                throw new InvalidOperationException("Access denied");
            }

            var results = await _clientStore
                          .GetClientsAsync(clientSearchCriteria, cancellationToken);

            return(new PaginationResult <ClientEntity>
            {
                PageIndex = results.PageIndex,
                PageSize = results.PageSize,
                TotalCount = results.TotalCount,
                Items = results.Items.Select(i => new ClientEntity(i))
            });
        }