"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.start = start;
exports.startClass = startClass;
exports.startUnit = startUnit;
const fromSpec_1 = require("./spec/fromSpec");
const fromUnitBundle_1 = require("./spec/fromUnitBundle");
const weakMerge_1 = require("./weakMerge");
function start(system, bundle, play = true) {
    const { classes } = system;
    const { spec } = bundle;
    if (!spec.id) {
        system.newSpec(spec);
    }
    const specs = (0, weakMerge_1.weakMerge)(bundle.specs ?? {}, system.specs);
    const Class = (0, fromSpec_1.fromSpec)(spec, specs, classes, {});
    return startClass(system, Class, play);
}
function startClass(system, Class, play = true) {
    const graph = new Class(system);
    if (play) {
        graph.play();
    }
    return graph;
}
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);
}
//# sourceMappingURL=start.js.map