"use strict";
/*
 * Copyright (c) 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.mergeQuerySort = exports.buildQuerySort = void 0;
const smob_1 = require("smob");
const type_1 = require("./type");
const utils_1 = require("../../utils");
function buildQuerySort(data) {
    if (typeof data === 'undefined') {
        return [];
    }
    if (typeof data === 'string') {
        return [data];
    }
    return (0, utils_1.flattenToKeyPathArray)(data, {
        transformer: ((input, output, path) => {
            if (typeof input === 'string' &&
                path &&
                (input === type_1.SortDirection.ASC ||
                    input === type_1.SortDirection.DESC)) {
                if (input === type_1.SortDirection.DESC) {
                    output.push(`-${path}`);
                }
                else {
                    output.push(path);
                }
                return true;
            }
            return undefined;
        }),
    });
}
exports.buildQuerySort = buildQuerySort;
function mergeQuerySort(target, source) {
    return (0, smob_1.mergeArrays)(target || [], source || [], true);
}
exports.mergeQuerySort = mergeQuerySort;
//# sourceMappingURL=build.js.map