"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = __importDefault(require("../types"));
const route_component_1 = require("../route/route-component");
const libs_1 = require("../libs");
const soa_plugin_1 = require("./soa-plugin");
const environment_plugin_1 = require("../environment/environment-plugin");
const service_plugin_1 = require("../service/service-plugin");
const service_component_1 = require("../service/service-component");
const datalayer_plugin_1 = require("../datalayer/datalayer-plugin");
const datalayer_component_1 = require("../datalayer/datalayer-component");
const storage_plugin_1 = require("../storage/storage-plugin");
const storage_component_1 = require("../storage/storage-component");
exports.SERVICEORIENTED_INSTANCE_TYPE = "ServiceOrientedComponent";
/**
 * The SinglePageApp is an infrastructure and must implement [[IInfrastructure]]
 *
 * @param props
 */
exports.default = (props) => {
    //console.log ("isomorphic: ",props );
    const infProps = {
        // allows to identify this component as Infrastructure
        infrastructureType: types_1.default.INFRASTRUCTURE_TYPE_CONFIGURATION,
        instanceId: props.stackName,
        instanceType: exports.SERVICEORIENTED_INSTANCE_TYPE,
        // only load plugins during compilation
        createPlugins: (configPath, stage, parserMode) => props.infrastructureMode === "COMPILATION" ? [
            // be able to process IsomorphicApps (as top-level-node)
            soa_plugin_1.SoaPlugin({
                stage: stage,
                parserMode: parserMode,
                buildPath: props.buildPath,
                configFilePath: configPath
            }),
            // ServiceOriented apps can have different environments
            environment_plugin_1.EnvironmentPlugin({
                stage: stage,
                parserMode: parserMode
            }),
            service_plugin_1.ServicePlugin({}),
            datalayer_plugin_1.DataLayerPlugin({
                parserMode: parserMode,
                buildPath: props.buildPath,
                configFilePath: configPath,
            }),
            storage_plugin_1.StoragePlugin({
                buildPath: props.buildPath,
                parserMode: parserMode
            })
        ] : []
    };
    // TODO maybe edit to support the web-mode?!
    const spaProps = {
        id: props.stackName,
        routes: libs_1.getChildrenArray(props.children)
            .filter(child => route_component_1.isRoute(child)),
        redirects: [],
        services: libs_1.findComponentRecursively(props.children, c => service_component_1.isService(c) || storage_component_1.isStorage(c)),
        dataLayerId: libs_1.findComponentRecursively(props.children, datalayer_component_1.isDataLayer).reduce((res, dl) => res ? res : dl.id, undefined)
    };
    return Object.assign(props, infProps, spaProps);
};
function isServiceOrientedApp(component) {
    return component !== undefined &&
        component.instanceType === exports.SERVICEORIENTED_INSTANCE_TYPE;
}
exports.isServiceOrientedApp = isServiceOrientedApp;
//# sourceMappingURL=soa-component.js.map