"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.buildQuery = void 0;
const parameter_1 = require("../parameter");
const constants_1 = require("../constants");
const utils_1 = require("../utils");
function buildQuery(input) {
    if (typeof input === 'undefined' ||
        input === null) {
        return '';
    }
    const query = {};
    if (typeof input[constants_1.Parameter.FIELDS] !== 'undefined' ||
        typeof input[constants_1.URLParameter.FIELDS] !== 'undefined') {
        query[constants_1.URLParameter.FIELDS] = (0, parameter_1.mergeQueryFields)((0, parameter_1.buildQueryFields)(input[constants_1.Parameter.FIELDS]), (0, parameter_1.buildQueryFields)(input[constants_1.URLParameter.FIELDS]));
    }
    if (typeof input[constants_1.Parameter.FILTERS] !== 'undefined' ||
        typeof input[constants_1.URLParameter.FILTERS] !== 'undefined') {
        query[constants_1.URLParameter.FILTERS] = (0, parameter_1.mergeQueryFilters)((0, parameter_1.buildQueryFilters)(input[constants_1.Parameter.FILTERS]), (0, parameter_1.buildQueryFilters)(input[constants_1.URLParameter.FILTERS]));
    }
    if (typeof input[constants_1.Parameter.PAGINATION] !== 'undefined' ||
        typeof input[constants_1.URLParameter.PAGINATION] !== 'undefined') {
        query[constants_1.URLParameter.PAGINATION] = (0, parameter_1.mergeQueryPagination)(input[constants_1.Parameter.PAGINATION], input[constants_1.URLParameter.PAGINATION]);
    }
    if (typeof input[constants_1.Parameter.RELATIONS] !== 'undefined' ||
        typeof input[constants_1.URLParameter.RELATIONS] !== 'undefined') {
        query[constants_1.URLParameter.RELATIONS] = (0, parameter_1.mergeQueryRelations)((0, parameter_1.buildQueryRelations)(input[constants_1.Parameter.RELATIONS]), (0, parameter_1.buildQueryRelations)(input[constants_1.URLParameter.RELATIONS]));
    }
    if (typeof input[constants_1.Parameter.SORT] !== 'undefined' ||
        typeof input[constants_1.URLParameter.SORT] !== 'undefined') {
        query[constants_1.URLParameter.SORT] = (0, parameter_1.mergeQuerySort)((0, parameter_1.buildQuerySort)(input[constants_1.Parameter.SORT]), (0, parameter_1.buildQuerySort)(input[constants_1.URLParameter.SORT]));
    }
    return (0, utils_1.buildURLQueryString)(query);
}
exports.buildQuery = buildQuery;
//# sourceMappingURL=module.js.map