import { getRegistrations } from "../../events/api/registrations";
import { eventAttendeeToSearchResult } from "./hubEventsHelpers/eventAttendeeToSearchResult";
import { processAttendeeOptions } from "./hubEventsHelpers/processAttendeeOptions";
import { processAttendeeFilters } from "./hubEventsHelpers/processAttendeeFilters";
/**
 * @private
 * Execute event attendees search against the Events API
 * @param query
 * @param options
 * @returns
 */
export async function hubSearchEventAttendees(query, options) {
    const processedFilters = processAttendeeFilters(query);
    const processedOptions = processAttendeeOptions(options);
    const data = Object.assign(Object.assign({}, processedFilters), processedOptions);
    const { items, nextStart, total } = await getRegistrations(Object.assign(Object.assign({}, options.requestOptions), { data }));
    const results = await Promise.all(items.map((eventAttendee) => eventAttendeeToSearchResult(eventAttendee, options)));
    const hasNext = nextStart > -1;
    return {
        total,
        results,
        hasNext,
        next: () => {
            if (!hasNext) {
                throw new Error("No more hub events for the given query and options");
            }
            return hubSearchEventAttendees(query, Object.assign(Object.assign({}, options), { start: nextStart }));
        },
    };
}
//# sourceMappingURL=hubSearchEventAttendees.js.map