/**
 * Reading facilities that allow reading different versions of a metadata file.
 * @author Louis-Dominique Dubeau
 * @license MPL 2.0
 * @copyright Mangalam Research Center for Buddhist Languages
 */
define(["require", "exports", "./metadata-reader-v1", "./metadata-reader-v2"], function (require, exports, metadata_reader_v1_1, metadata_reader_v2_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**
     * A metadata reader that automatically handles different versions of the
     * metadata format.
     */
    class MetadataMultiversionReader {
        static init() {
            const readers = [metadata_reader_v1_1.MetadataReaderV1, metadata_reader_v2_1.MetadataReaderV2];
            for (const reader of readers) {
                MetadataMultiversionReader.versionToConstructor[reader.version] = reader;
            }
        }
        read(object) {
            // tslint:disable-next-line:no-any
            const version = object.version;
            if (version === undefined) {
                throw new Error("no version field, cannot decode metadata");
            }
            const ctor = MetadataMultiversionReader.versionToConstructor[version];
            if (ctor === undefined) {
                throw new Error(`cannot handle version ${version}`);
            }
            return new ctor().read(object);
        }
    }
    MetadataMultiversionReader.versionToConstructor = Object.create(null);
    exports.MetadataMultiversionReader = MetadataMultiversionReader;
    MetadataMultiversionReader.init();
});
//  LocalWords:  MPL
//# sourceMappingURL=metadata-multiversion-reader.js.map