"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.processAttendeeFilters = processAttendeeFilters;
const types_1 = require("../../../events/api/types");
const getOptionalPredicateStringsByKey_1 = require("./getOptionalPredicateStringsByKey");
const getPredicateValuesByKey_1 = require("./getPredicateValuesByKey");
function processAttendeeFilters(query) {
    const processedFilters = {
        eventId: query.properties.eventId,
    };
    const useElseJoin = (value, defaults) => (value === null || value === void 0 ? void 0 : value.length) ? value : defaults.map((val) => val.toLowerCase()).join(",");
    const userId = (0, getOptionalPredicateStringsByKey_1.getOptionalPredicateStringsByKey)(query.filters, "userId");
    if (userId === null || userId === void 0 ? void 0 : userId.length) {
        processedFilters.userId = userId;
    }
    const term = (0, getPredicateValuesByKey_1.getPredicateValuesByKey)(query.filters, "term");
    if (term.length) {
        processedFilters.name = term[0];
    }
    processedFilters.type = useElseJoin((0, getOptionalPredicateStringsByKey_1.getOptionalPredicateStringsByKey)(query.filters, "attendanceType"), [types_1.EventAttendanceType.VIRTUAL, types_1.EventAttendanceType.IN_PERSON]);
    processedFilters.role = useElseJoin((0, getOptionalPredicateStringsByKey_1.getOptionalPredicateStringsByKey)(query.filters, "role"), [
        types_1.RegistrationRole.OWNER,
        types_1.RegistrationRole.ORGANIZER,
        types_1.RegistrationRole.ATTENDEE,
    ]);
    processedFilters.status = useElseJoin((0, getOptionalPredicateStringsByKey_1.getOptionalPredicateStringsByKey)(query.filters, "status"), [
        types_1.RegistrationStatus.PENDING,
        types_1.RegistrationStatus.ACCEPTED,
        types_1.RegistrationStatus.DECLINED,
        types_1.RegistrationStatus.BLOCKED,
    ]);
    const updatedDateRange = (0, getPredicateValuesByKey_1.getPredicateValuesByKey)(query.filters, "updatedDateRange");
    if (updatedDateRange.length) {
        processedFilters.updatedAtBefore = new Date(updatedDateRange[0].to).toISOString();
        processedFilters.updatedAtAfter = new Date(updatedDateRange[0].from).toISOString();
    }
    return processedFilters;
}
//# sourceMappingURL=processAttendeeFilters.js.map