"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const evaluateBundleSpec_1 = require("../../../../../spec/evaluate/evaluateBundleSpec");
const fromUnitBundle_1 = require("../../../../../spec/fromUnitBundle");
const validate_1 = require("../../../../../spec/validate");
const _ids_1 = require("../../../../_ids");
class FromUnitBundle extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['bundle'],
            o: ['unit'],
        }, {
            output: {},
        }, system, _ids_1.ID_FROM_UNIT_BUNDLE);
    }
    f({ bundle }, done, fail) {
        const { specs, classes } = this.__system;
        (0, evaluateBundleSpec_1.evaluateUnitBundleSpec)(bundle, specs, classes);
        let unit;
        if (!(0, validate_1.validateUnitBundleSpec)(bundle)) {
            fail('invalid bundle spec');
            return;
        }
        try {
            unit = (0, fromUnitBundle_1.fromUnitBundle)(bundle, this.__system.specs, {});
        }
        catch (err) {
            fail(err.message);
            return;
        }
        done({ unit });
    }
}
exports.default = FromUnitBundle;
//# sourceMappingURL=index.js.map