"use strict";
/*
 * Copyright (c) 2021-2022.
 * Author Peter Placzek (tada5hi)
 * For the full copyright and license information,
 * view the LICENSE file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeQueryFilters = exports.buildQueryFilters = void 0;
const smob_1 = require("smob");
const utils_1 = require("../../utils");
function buildQueryFilters(data) {
    if (typeof data === 'undefined') {
        return {};
    }
    return (0, utils_1.flattenNestedObject)(data, {
        transformer: (input, output, key) => {
            if (typeof input === 'undefined') {
                output[key] = null;
                return true;
            }
            if (Array.isArray(input)) {
                // preserve null values
                const data = [];
                for (let i = 0; i < input.length; i++) {
                    if (input[i] === null) {
                        input[i] = 'null';
                    }
                    if (typeof input[i] === 'number') {
                        input[i] = `${input[i]}`;
                    }
                    if (typeof input[i] === 'string') {
                        data.push(input[i]);
                    }
                }
                output[key] = data.join(',');
                return true;
            }
            return undefined;
        },
    });
}
exports.buildQueryFilters = buildQueryFilters;
function mergeQueryFilters(target, source) {
    return (0, smob_1.merge)({}, target || {}, source || {});
}
exports.mergeQueryFilters = mergeQueryFilters;
//# sourceMappingURL=build.js.map