import { TaJson } from "ta-json";
import { InvalidOperationError } from "../errors/invalid-operation-error";
import { FacetResponseResource } from "../models/search/facet-response-resource";
export class AllFacetValuesChildrenConverter {
    /**
     * Serializes a mapping of strings to array of FacetResponseResource into a JSON object.
     *
     * @param value - A mapping of strings to array of FacetResponseResource
     *
     * @returns The serialized value.
     */
    serialize(children) {
        const result = Object.keys(children).reduce((serialized, key) => {
            var _a;
            const entries = (_a = children[key]) === null || _a === void 0 ? void 0 : _a.map(entry => TaJson.serialize(entry));
            return Object.assign(Object.assign({}, serialized), { [key]: entries });
        }, {});
        return result;
    }
    /**
     * Deserializes a JSON object into a mapping of strings to array of FacetResponseResource.
     *
     * @param value - The serialized value
     *
     * @returns A mapping of strings to array of FacetResponseResource.
     */
    deserialize(value) {
        if (!value) {
            return {};
        }
        else if (typeof value !== "object") {
            throw new InvalidOperationError(`Expected a value of type 'JSON object', but value was of type '${typeof value}'.`);
        }
        const result = Object.keys(value).reduce((current, key) => {
            var _a;
            const entries = (_a = value[key]) === null || _a === void 0 ? void 0 : _a.map(entry => TaJson.deserialize(entry, FacetResponseResource));
            return Object.assign(Object.assign({}, current), { [key]: entries });
        }, {});
        return result;
    }
}
//# sourceMappingURL=all-facet-values-children-converter.js.map