var _this = this;
import * as tslib_1 from "tslib";
import { Http } from "@intelligentgraphics/ig.utilities";
import { parseModelsFile } from "./Formats";
export var 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*/, Http.getJSON(settings.DataPath, {
                    addTimestamp: true,
                })];
            case 1:
                data = _a.sent();
                return [2 /*return*/, createDataAPI(data, settings)];
        }
    });
}); };
export var createDataAPI = function (rawData, settings) {
    var data = 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;
        },
    };
};
