class ArchiveQuery {

    public ArchivedMessages execute() throws XMLSemanticError {
        ArchiveFilter archiveFilter = new ArchiveFilter(archiveId, query.getX());
        QuerySet querySet = query.getSet();

        if (querySet.lastPage()) {
            long pageSize = querySet.pageSize().orElseThrow(
                    () -> new IllegalArgumentException("Page size must be defined when requesting last page"));
            return archive.fetchLastPageSortedByOldestFirst(archiveFilter, pageSize);
        } else {
            return archive.fetchSortedByOldestFirst(archiveFilter, querySet);
        }
    }

    public  ArchiveQuery(MessageArchive archive, Entity archiveId, Query query);

}