public SearchResults<GroupInformation> search(DbSession dbSession, GroupSearchRequest groupSearchRequest) {
    GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession);
    GroupQuery query = toGroupQuery(groupSearchRequest);

    int limit = dbClient.groupDao().countByQuery(dbSession, query);
    if (groupSearchRequest.page() == 0) {
      return new SearchResults<>(List.of(), limit);
    }

    List<GroupDto> groups = dbClient.groupDao().selectByQuery(dbSession, query, groupSearchRequest.page(), groupSearchRequest.pageSize());
    List<String> groupUuids = extractGroupUuids(groups);
    Map<String, Boolean> groupUuidToIsManaged = managedInstanceService.getGroupUuidToManaged(dbSession, new HashSet<>(groupUuids));

    List<GroupInformation> results = groups.stream()
      .map(groupDto -> toGroupInformation(groupDto, defaultGroup.getUuid(), groupUuidToIsManaged))
      .toList();

    return new SearchResults<>(results, limit);
  }
@Test
  public void search_whenInstanceNotManagedAndManagedIsTrue_throws() {
    assertThatExceptionOfType(BadRequestException.class)
      .isThrownBy(() -> groupService.search(dbSession, new GroupSearchRequest("query", true, 5, 24)))
      .withMessage("The 'managed' parameter is only available for managed instances.");
  }