"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startUnit = exports.startClass = exports.start = void 0;
const fromSpec_1 = require("./spec/fromSpec");
const fromUnitBundle_1 = require("./spec/fromUnitBundle");
const weakMerge_1 = require("./weakMerge");
function start(system, bundle, play = true) {
    var _a;
    const { classes } = system;
    const { spec } = bundle;
    if (!spec.id) {
        system.newSpec(spec);
    }
    const specs = (0, weakMerge_1.weakMerge)((_a = bundle.specs) !== null && _a !== void 0 ? _a : {}, system.specs);
    const Class = (0, fromSpec_1.fromSpec)(spec, specs, classes, {});
    return startClass(system, Class, true);
}
exports.start = start;
function startClass(system, Class, play = true) {
    const graph = new Class(system);
    system.graphs.push(graph);
    graph.play();
    return graph;
}
exports.startClass = startClass;
function startUnit(system, bundle, play = true) {
    if (bundle.specs) {
        system.injectSpecs(bundle.specs);
    }
    const Class = (0, fromUnitBundle_1.fromUnitBundle)(bundle, system.specs, {});
    return startClass(system, Class, play);
}
exports.startUnit = startUnit;
//# sourceMappingURL=start.js.map