"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeFilterConditionTest = void 0;
exports.getParsedSearchTermsByFieldType = getParsedSearchTermsByFieldType;
exports.getVarTypeOfByColumnFieldType = getVarTypeOfByColumnFieldType;
const index_js_1 = require("../enums/index.js");
const booleanFilterCondition_js_1 = require("./booleanFilterCondition.js");
const collectionSearchFilterCondition_js_1 = require("./collectionSearchFilterCondition.js");
const numberFilterCondition_js_1 = require("./numberFilterCondition.js");
const dateFilterCondition_js_1 = require("./dateFilterCondition.js");
const objectFilterCondition_js_1 = require("./objectFilterCondition.js");
const stringFilterCondition_js_1 = require("./stringFilterCondition.js");
const filterUtilities_js_1 = require("./filterUtilities.js");
const utilities_js_1 = require("../services/utilities.js");
/** Execute mapped condition (per field type) for each cell in the grid */
exports.executeFilterConditionTest = ((options, parsedSearchTerms) => {
    // when using a multi-select ('IN' operator) we will not use the field type but instead go directly with a collection search
    if ((0, filterUtilities_js_1.isCollectionOperator)(options.operator)) {
        return (0, collectionSearchFilterCondition_js_1.executeCollectionSearchFilterCondition)(options);
    }
    // From a more specific field type (dateIso, dateEuro, text, readonly, ...), get the more generalized type (boolean, date, number, object, text)
    const generalizedType = getVarTypeOfByColumnFieldType(options.filterSearchType || options.fieldType);
    // execute the mapped type, or default to String condition check
    switch (generalizedType) {
        case 'boolean':
            // the parsedSearchTerms should be single value (result came from getFilterParsedBoolean() method)
            return (0, booleanFilterCondition_js_1.executeBooleanFilterCondition)(options, parsedSearchTerms);
        case 'date':
            return (0, dateFilterCondition_js_1.executeDateFilterCondition)(options, (parsedSearchTerms || []));
        case 'number':
            return (0, numberFilterCondition_js_1.executeNumberFilterCondition)(options, (parsedSearchTerms || []));
        case 'object':
            // the parsedSearchTerms should be single value (result came from getFilterParsedObjectResult() method)
            return (0, objectFilterCondition_js_1.executeObjectFilterCondition)(options, parsedSearchTerms);
        case 'string':
        default:
            // the parsedSearchTerms should be single value (result came from getFilterParsedText() method)
            return (0, stringFilterCondition_js_1.executeStringFilterCondition)(options, (parsedSearchTerms || []));
    }
});
/**
 * From our search filter value(s), get their parsed value(s), for example a "dateIso" filter will be parsed as Date object.
 * Then later when we execute the filtering checks, we won't need to re-parse all search value(s) again and again.
 * So this is called only once, for each search filter that is, prior to running the actual filter condition checks on each cell afterward.
 */
function getParsedSearchTermsByFieldType(inputSearchTerms, inputFilterSearchType) {
    const generalizedType = getVarTypeOfByColumnFieldType(inputFilterSearchType);
    let parsedSearchValues;
    // parse the search value(s), the Date & Numbers could be in a range and so we will return an array for them
    // any other type will return a single search value
    switch (generalizedType) {
        case 'boolean':
            parsedSearchValues = (0, booleanFilterCondition_js_1.getFilterParsedBoolean)(inputSearchTerms);
            break;
        case 'date':
            parsedSearchValues = (0, dateFilterCondition_js_1.getFilterParsedDates)(inputSearchTerms, inputFilterSearchType);
            break;
        case 'number':
            parsedSearchValues = (0, numberFilterCondition_js_1.getFilterParsedNumbers)(inputSearchTerms);
            break;
        case 'object':
            parsedSearchValues = (0, objectFilterCondition_js_1.getFilterParsedObjectResult)(inputSearchTerms);
            break;
        case 'string':
            parsedSearchValues = (0, stringFilterCondition_js_1.getFilterParsedText)(inputSearchTerms);
            break;
    }
    return parsedSearchValues;
}
/**
 * From a more specific field type, let's return a simple and more general type (boolean, date, number, object, text)
 * @param fieldType - specific field type
 * @returns generalType - general field type
 */
function getVarTypeOfByColumnFieldType(fieldType) {
    if ((0, utilities_js_1.isColumnDateType)(fieldType)) {
        return 'date';
    }
    // return general field type
    switch (fieldType) {
        case index_js_1.FieldType.boolean:
            return 'boolean';
        case index_js_1.FieldType.integer:
        case index_js_1.FieldType.float:
        case index_js_1.FieldType.number:
            return 'number';
        case index_js_1.FieldType.object:
            return 'object';
        case index_js_1.FieldType.string:
        case index_js_1.FieldType.text:
        case index_js_1.FieldType.password:
        case index_js_1.FieldType.readonly:
        default:
            return 'string';
    }
}
//# sourceMappingURL=filterConditionProcesses.js.map