"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PredicateInternalApi = void 0;
const ApiBase_1 = require("../Implementation/ApiBase");
class PredicateInternalApi extends ApiBase_1.ApiBase {
    IsInOrNotInPredicate(predicate) {
        return predicate?.PredicateId === 'In' || predicate?.PredicateId === 'NotIn';
    }
    IsInOrNotInPredicateDef(predicateDef) {
        return predicateDef && ['In', 'NotIn'].includes(predicateDef.id);
    }
    /**
     * Get all Filter Predicate Definitions - System and Custom
     */
    getFilterPredicateDefs(scope) {
        return this.mergeSystemAndCustomPredicates(this.getSystemFilterPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('columnFilter'));
    }
    shouldUseCaseSensitivePredicates(column) {
        const caseSensitivePredicates = this.getPredicateOptions().caseSensitivePredicates;
        if (typeof caseSensitivePredicates === 'function') {
            return caseSensitivePredicates(this.getAdaptableInternalApi().buildAdaptableColumnContext(column));
        }
        return caseSensitivePredicates;
    }
    shouldEvaluateInPredicateUsingTime(column) {
        const evaluateInPredicateUsingTime = this.getPredicateOptions().evaluateInPredicateUsingTime;
        if (typeof evaluateInPredicateUsingTime === 'function') {
            return evaluateInPredicateUsingTime(this.getAdaptableInternalApi().buildAdaptableColumnContext(column));
        }
        return evaluateInPredicateUsingTime;
    }
    getSystemFilterPredicateIds(scope) {
        const systemFilterPredicates = this.getPredicateOptions().systemFilterPredicates;
        if (typeof systemFilterPredicates === 'function') {
            const systemPredicateContext = {
                ...this.getAdaptableInternalApi().buildBaseContext(),
                systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('columnFilter'),
                moduleScope: 'columnFilter',
                columnScope: scope,
            };
            return systemFilterPredicates(systemPredicateContext);
        }
        return systemFilterPredicates;
    }
    /**
     * Get all Alert Predicate Definitions - System and Custom
     */
    getAlertPredicateDefs(scope) {
        return this.mergeSystemAndCustomPredicates(this.getSystemAlertPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('alert'));
    }
    getSystemAlertPredicateIds(scope) {
        const systemAlertPredicates = this.getPredicateOptions().systemAlertPredicates;
        if (typeof systemAlertPredicates === 'function') {
            const systemPredicateContext = {
                ...this.getAdaptableInternalApi().buildBaseContext(),
                systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('alert'),
                moduleScope: 'alert',
                columnScope: scope,
            };
            return systemAlertPredicates(systemPredicateContext);
        }
        return systemAlertPredicates;
    }
    getSystemBadgeStylePredicateIds(scope) {
        const systemBadgeStylePredicates = this.getPredicateOptions().systemBadgeStylePredicates;
        if (typeof systemBadgeStylePredicates === 'function') {
            const systemPredicateContext = {
                ...this.getAdaptableInternalApi().buildBaseContext(),
                systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('badgeStyle'),
                moduleScope: 'badgeStyle',
                columnScope: scope,
            };
            return systemBadgeStylePredicates(systemPredicateContext);
        }
        return systemBadgeStylePredicates;
    }
    /**
     * Get all Format Column Predicate Definitions - System and Custom
     */
    getFormatColumnPredicateDefs(scope) {
        return this.mergeSystemAndCustomPredicates(this.getSystemFormatColumnPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('formatColumn'));
    }
    getSystemFormatColumnPredicateIds(scope) {
        const systemFormatColumnPredicates = this.getPredicateOptions().systemFormatColumnPredicates;
        if (typeof systemFormatColumnPredicates === 'function') {
            const systemPredicateContext = {
                ...this.getAdaptableInternalApi().buildBaseContext(),
                systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('formatColumn'),
                moduleScope: 'formatColumn',
                columnScope: scope,
            };
            return systemFormatColumnPredicates(systemPredicateContext);
        }
        return systemFormatColumnPredicates;
    }
    /**
     * Get all Flashing Cell Predicate Definitions - System and Custom
     */
    getFlashingCellPredicateDefs(scope) {
        return this.mergeSystemAndCustomPredicates(this.getSystemFlashingCellPredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('flashingcell'));
    }
    getSystemFlashingCellPredicateIds(scope) {
        const systemFlashingCellPredicates = this.getPredicateOptions().systemFlashingCellPredicates;
        if (typeof systemFlashingCellPredicates === 'function') {
            const systemPredicateContext = {
                systemPredicateDefs: this.getPredicateApi().getSystemPredicateDefsByModuleScope('flashingcell'),
                moduleScope: 'flashingcell',
                columnScope: scope,
                ...this.getAdaptableInternalApi().buildBaseContext(),
            };
            return systemFlashingCellPredicates(systemPredicateContext);
        }
        return systemFlashingCellPredicates;
    }
    /**
     * Gets the correct Equality-type System Predicate for a particular DataType
     * @param dataType DataType of Column
     */
    getEqualityPredicateForDataType(dataType) {
        let predicateId;
        switch (dataType) {
            case 'number':
                predicateId = 'Equals';
                break;
            case 'date':
                predicateId = 'On';
                break;
            case 'text':
                predicateId = 'Is';
                break;
            default:
                predicateId = 'Equals';
                break;
        }
        return predicateId;
    }
    /**
     * Get all Badge Style Predicate Definitions - System and Custom
     */
    getBadgeStylePredicateDefs(scope) {
        return this.mergeSystemAndCustomPredicates(this.getSystemBadgeStylePredicateIds(scope)?.map((predicateId) => this.getPredicateApi().getPredicateDefById(predicateId)), this.getPredicateApi().getCustomPredicateDefs()).filter((predicateDef) => predicateDef.moduleScope.includes('badgeStyle'));
    }
    /**
     * Merges System and Custom Predicate Definitions but ensures that Custom ones take precedence
     * (i.e. if there is a Custom Predicate with the same Id as a System one, the Custom one is used)
     */
    mergeSystemAndCustomPredicates(systemDefs, customDefs) {
        const systemDefsToUse = systemDefs.map((systemDef) => {
            const customDef = customDefs.find((customDef) => customDef.id === systemDef.id);
            return customDef ? customDef : systemDef;
        });
        const customDefsToUse = customDefs.filter((customDef) => !systemDefsToUse.find((systemDef) => systemDef.id === customDef.id));
        return [...systemDefsToUse, ...customDefsToUse];
    }
}
exports.PredicateInternalApi = PredicateInternalApi;
