"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeMetadataFilterScopeField = serializeMetadataFilterScopeField;
exports.deserializeMetadataFilterScopeField = deserializeMetadataFilterScopeField;
exports.serializeMetadataFilter = serializeMetadataFilter;
exports.deserializeMetadataFilter = deserializeMetadataFilter;
const metadataFilterValue_1 = require("./metadataFilterValue");
const metadataFilterValue_2 = require("./metadataFilterValue");
const errors_1 = require("../box/errors");
const json_1 = require("../serialization/json");
const json_2 = require("../serialization/json");
function serializeMetadataFilterScopeField(val) {
    return val;
}
function deserializeMetadataFilterScopeField(val) {
    if (val == 'global') {
        return val;
    }
    if (val == 'enterprise') {
        return val;
    }
    if (val == 'enterprise_{enterprise_id}') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize MetadataFilterScopeField",
    });
}
function serializeMetadataFilter(val) {
    return {
        ['scope']: val.scope == void 0
            ? val.scope
            : serializeMetadataFilterScopeField(val.scope),
        ['templateKey']: val.templateKey,
        ['filters']: val.filters == void 0
            ? val.filters
            : Object.fromEntries(Object.entries(val.filters).map(([k, v]) => [
                k,
                (0, metadataFilterValue_1.serializeMetadataFilterValue)(v),
            ])),
    };
}
function deserializeMetadataFilter(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({ message: 'Expecting a map for "MetadataFilter"' });
    }
    const scope = val.scope == void 0
        ? void 0
        : deserializeMetadataFilterScopeField(val.scope);
    if (!(val.templateKey == void 0) && !(0, json_1.sdIsString)(val.templateKey)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "templateKey" of type "MetadataFilter"',
        });
    }
    const templateKey = val.templateKey == void 0 ? void 0 : val.templateKey;
    if (!(val.filters == void 0) && !(0, json_2.sdIsMap)(val.filters)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting object for "filters" of type "MetadataFilter"',
        });
    }
    const filters = val.filters == void 0
        ? void 0
        : (0, json_2.sdIsMap)(val.filters)
            ? Object.fromEntries(Object.entries(val.filters).map(([k, v]) => [
                k,
                (0, metadataFilterValue_2.deserializeMetadataFilterValue)(v),
            ]))
            : {};
    return {
        scope: scope,
        templateKey: templateKey,
        filters: filters,
    };
}
//# sourceMappingURL=metadataFilter.js.map