import { EventAttendanceType, RegistrationRole, RegistrationStatus, } from "../../../events/api/types";
import { getOptionalPredicateStringsByKey } from "./getOptionalPredicateStringsByKey";
import { getPredicateValuesByKey } from "./getPredicateValuesByKey";
export 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 = getOptionalPredicateStringsByKey(query.filters, "userId");
    if (userId === null || userId === void 0 ? void 0 : userId.length) {
        processedFilters.userId = userId;
    }
    const term = getPredicateValuesByKey(query.filters, "term");
    if (term.length) {
        processedFilters.name = term[0];
    }
    processedFilters.type = useElseJoin(getOptionalPredicateStringsByKey(query.filters, "attendanceType"), [EventAttendanceType.VIRTUAL, EventAttendanceType.IN_PERSON]);
    processedFilters.role = useElseJoin(getOptionalPredicateStringsByKey(query.filters, "role"), [
        RegistrationRole.OWNER,
        RegistrationRole.ORGANIZER,
        RegistrationRole.ATTENDEE,
    ]);
    processedFilters.status = useElseJoin(getOptionalPredicateStringsByKey(query.filters, "status"), [
        RegistrationStatus.PENDING,
        RegistrationStatus.ACCEPTED,
        RegistrationStatus.DECLINED,
        RegistrationStatus.BLOCKED,
    ]);
    const updatedDateRange = 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