"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ig_utilities_1 = require("@intelligentgraphics/ig.utilities");
var Formats_1 = require("./Formats");
exports.loadData = function (settings) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
    var data;
    return tslib_1.__generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, ig_utilities_1.Http.getJSON(settings.DataPath, {
                    addTimestamp: true,
                })];
            case 1:
                data = _a.sent();
                return [2 /*return*/, exports.createDataAPI(data, settings)];
        }
    });
}); };
exports.createDataAPI = function (rawData, settings) {
    var data = Formats_1.parseModelsFile(rawData, {
        imageBasePath: settings.ResourceBasePath,
    });
    var getArticle = function (articleId) {
        var article = data.find(function (article) { return article.id === articleId; });
        if (article === undefined) {
            throw new Error("Could not find data for article id \"" + articleId + "\"");
        }
        return article;
    };
    return {
        getCatalogItems: function () { return data.map(function (article) { return article.catalogItem; }); },
        getProperties: function (articleId) {
            var article = getArticle(articleId);
            return article.properties;
        },
        getDefaultConfiguration: function (articleId) {
            var article = getArticle(articleId);
            return article.defaultConfiguration;
        },
    };
};
