/**
 * Copyright (c) 2020-present, Goldman Sachs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { UnsupportedOperationError, } from '@finos/legend-shared';
import { serialize, deserialize } from 'serializr';
import { V1_BaseDataResolver, V1_ReferenceDataResolver, } from '../../../model/data/V1_DataResolver.js';
import { V1_deserializeEmbeddedDataType, V1_serializeEmbeddedDataType, } from './V1_DataElementSerializationHelper.js';
import { V1_packageableElementPointerModelSchema } from './V1_CoreSerializationHelper.js';
var V1_DataResolverType;
(function (V1_DataResolverType) {
    V1_DataResolverType["BASE_DATA_RESOLVER"] = "baseDataResolver";
    V1_DataResolverType["REFERENCE_DATA_RESOLVER"] = "referenceDataResolver";
})(V1_DataResolverType || (V1_DataResolverType = {}));
export const V1_serializeDataResolver = (protocol, plugins) => {
    if (protocol instanceof V1_BaseDataResolver) {
        return {
            _type: V1_DataResolverType.BASE_DATA_RESOLVER,
            data: V1_serializeEmbeddedDataType(protocol.data, plugins),
            elementPointer: serialize(V1_packageableElementPointerModelSchema, protocol.elementPointer),
        };
    }
    else if (protocol instanceof V1_ReferenceDataResolver) {
        return {
            _type: V1_DataResolverType.REFERENCE_DATA_RESOLVER,
            elementPointer: serialize(V1_packageableElementPointerModelSchema, protocol.elementPointer),
        };
    }
    throw new UnsupportedOperationError(`Unable to serialize data resolver of type '${protocol.constructor.name}'`);
};
export const V1_deserializeDataResolver = (json, plugins) => {
    switch (json._type) {
        case V1_DataResolverType.BASE_DATA_RESOLVER: {
            const resolver = new V1_BaseDataResolver();
            resolver.elementPointer = deserialize(V1_packageableElementPointerModelSchema, json.elementPointer);
            resolver.data = V1_deserializeEmbeddedDataType(json.data, plugins);
            return resolver;
        }
        case V1_DataResolverType.REFERENCE_DATA_RESOLVER: {
            const resolver = new V1_ReferenceDataResolver();
            resolver.elementPointer = deserialize(V1_packageableElementPointerModelSchema, json.elementPointer);
            return resolver;
        }
        default:
            throw new UnsupportedOperationError(`Unable to deserialize data resolver of type '${json._type}'`);
    }
};
//# sourceMappingURL=V1_DataResolverSerializationHelper.js.map