class UsersManagementController extends AsyncAdaptor {

    private String view(Model model, String activeTab, String filter, int page, int size, boolean adminUser) {
        final CompletableFuture<ManageUserPageResource> activeUsers;
        final CompletableFuture<ManageUserPageResource> inactiveUsers;
        final CompletableFuture<RoleInvitePageResource> pendingUsers;
        if (adminUser) {
            activeUsers = async(() -> userRestService.getActiveUsers(filter, page - 1 , size).getSuccess());
            inactiveUsers = async(() -> userRestService.getInactiveUsers(filter, page - 1, size).getSuccess());
            pendingUsers = async(() -> inviteUserRestService.getPendingInternalUserInvites(filter, page - 1, size).getSuccess());
        }
        else {
            activeUsers = async(() -> userRestService.getActiveExternalUsers(filter, page - 1, size).getSuccess());
            inactiveUsers = async(() -> userRestService.getInactiveExternalUsers(filter, page - 1, size).getSuccess());
            pendingUsers = async(() -> new RoleInvitePageResource());
        }

        awaitAll(activeUsers, inactiveUsers, pendingUsers)
                .thenAccept((activeInternalUsers, inactiveInternalUsers, pendingInternalUserInvites) -> {
                    UserListViewModel viewModel = new UserListViewModel(
                            activeTab,
                            filter,
                            activeInternalUsers.getContent(),
                            inactiveInternalUsers.getContent(),
                            pendingInternalUserInvites.getContent(),
                            activeInternalUsers.getTotalElements(),
                            inactiveInternalUsers.getTotalElements(),
                            pendingInternalUserInvites.getTotalElements(),
                            new PaginationViewModel(activeInternalUsers),
                            new PaginationViewModel(inactiveInternalUsers),
                            new PaginationViewModel(pendingInternalUserInvites),
                            adminUser
                    );
                    model.addAttribute("model", viewModel);
                    model.addAttribute("externalRoleLinkEnabled", externalRoleLinkEnabled);
                });

        return "admin/users";
    }

}