import { Backend, } from "../Types";
import { IGXACatalogManager } from "./CatalogManager";
import { IGXELoader } from "./Loader";
import { IGXEProductDataManager } from "./ProductDataManager";
export class IGXEBackend extends Backend {
    async initializeManagers({ catalog, fetchData, dispatcherId, }) {
        const settings = catalog.Settings;
        if (settings.IGXA === undefined) {
            throw new Error("Can not initialize IGXACatalogManager without an igxa");
        }
        const igxa = await fetchData(settings.IGXA);
        const catalogManager = await IGXACatalogManager.Create({
            data: igxa,
            catalogLocale: "any",
            sourceId: dispatcherId,
        });
        const files = settings.IGXEAdditional || [];
        if (settings.IGXEPrimary) {
            files.push(settings.IGXEPrimary);
        }
        const igxeFiles = (await Promise.all(files.map(fetchData)));
        const nativeData = IGXELoader.readProductDataNative(igxeFiles.pop());
        const additionalData = igxeFiles.map(file => IGXELoader.readProductDataNative(file, true));
        const productManager = new IGXEProductDataManager({
            nativeData,
            additionalData,
            pushInterProductPropertysToTop: true,
            debugInfos: undefined,
        });
        return {
            catalogManager,
            productManager,
        };
    }
}
