"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hubSearchEventAttendees = hubSearchEventAttendees;
const registrations_1 = require("../../events/api/registrations");
const eventAttendeeToSearchResult_1 = require("./hubEventsHelpers/eventAttendeeToSearchResult");
const processAttendeeOptions_1 = require("./hubEventsHelpers/processAttendeeOptions");
const processAttendeeFilters_1 = require("./hubEventsHelpers/processAttendeeFilters");
/**
 * @private
 * Execute event attendees search against the Events API
 * @param query
 * @param options
 * @returns
 */
async function hubSearchEventAttendees(query, options) {
    const processedFilters = (0, processAttendeeFilters_1.processAttendeeFilters)(query);
    const processedOptions = (0, processAttendeeOptions_1.processAttendeeOptions)(options);
    const data = Object.assign(Object.assign({}, processedFilters), processedOptions);
    const { items, nextStart, total } = await (0, registrations_1.getRegistrations)(Object.assign(Object.assign({}, options.requestOptions), { data }));
    const results = await Promise.all(items.map((eventAttendee) => (0, eventAttendeeToSearchResult_1.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