"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildActivitiesFilterString = void 0;
var ramda_1 = require("ramda");
var types_1 = require("../types");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var buildActivityFilterClause = function (activityType) {
    if (activityType.startsWith('USER_') ||
        activityType.startsWith('COMMENT_') ||
        activityType.startsWith('SFDC_') ||
        activityType === types_1.ActivityTypes.ATTRIBUTE_UNMASKED) {
        return "startsWith(label, '".concat(activityType, "')");
    }
    else {
        return "equals(items.data.type, ".concat(activityType, ")");
    }
};
var buildAttributeFilterClause = function (attribute) {
    return "equals(items.delta.attributeType, '".concat(attribute.value, "')");
};
var buildSegmentFilterClause = function (segmentId) {
    return "equals(items.objectUri, 'segments/".concat(segmentId, "')");
};
var getFilterClauseBuilder = (0, ramda_1.cond)([
    [(0, ramda_1.equals)('users'), function () { return (0, mdm_sdk_1.multiValueFilter)(mdm_sdk_1.buildUserFilterClause); }],
    [(0, ramda_1.equals)('activities'), function () { return (0, mdm_sdk_1.multiValueFilter)(buildActivityFilterClause); }],
    [(0, ramda_1.equals)('sources'), function () { return (0, mdm_sdk_1.multiValueFilter)(mdm_sdk_1.buildSourceFilterClause); }],
    [(0, ramda_1.equals)('attributes'), function () { return (0, mdm_sdk_1.multiValueFilter)(buildAttributeFilterClause); }],
    [(0, ramda_1.equals)('entityTypes'), function () { return (0, mdm_sdk_1.multiValueFilter)(mdm_sdk_1.buildEntityTypeFilterClause); }],
    [(0, ramda_1.equals)('dateRange'), function () { return mdm_sdk_1.buildDateRangeFilterClause; }],
    [(0, ramda_1.equals)('entityUri'), function () { return mdm_sdk_1.buildEntityUriFilterClause; }],
    [(0, ramda_1.equals)('segmentId'), function () { return buildSegmentFilterClause; }],
    [(0, ramda_1.equals)('rawFilter'), function () { return ramda_1.identity; }]
]);
exports.buildActivitiesFilterString = (0, ramda_1.pipe)((0, ramda_1.defaultTo)({}), mdm_sdk_1.rejectEmptyValues, ramda_1.toPairs, (0, ramda_1.append)(['rawFilter', "not equals(user, 'collaboration-service')"]), (0, ramda_1.map)(function (_a) {
    var key = _a[0], value = _a[1];
    return getFilterClauseBuilder(key)(value);
}), mdm_sdk_1.rejectEmptyValues, (0, ramda_1.map)(mdm_sdk_1.wrapInBrackets), (0, ramda_1.join)(' and '));
