"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const deepSet_1 = require("../../../../../deepSet");
const evaluateDataValue_1 = require("../../../../../spec/evaluateDataValue");
const fromUnitBundle_1 = require("../../../../../spec/fromUnitBundle");
const util_1 = require("../../../../../spec/util");
const clone_1 = require("../../../../../util/clone");
const weakMerge_1 = require("../../../../../weakMerge");
const _ids_1 = require("../../../../_ids");
class SetInput extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['unit', 'name', 'data'],
            o: ['unit'],
        }, {}, system, _ids_1.ID_SET_INPUT);
    }
    f({ unit, name, data }, done, fail) {
        const { __bundle } = unit;
        const { unit: { id }, } = __bundle;
        const specs = (0, weakMerge_1.weakMerge)(this.__system.specs, __bundle.specs ?? {});
        const spec = (0, util_1.getSpec)(specs, id);
        const { inputs = {} } = spec;
        if (!inputs[name]) {
            fail('input not found');
            return;
        }
        const bundleClone = (0, clone_1.clone)(__bundle);
        (0, deepSet_1.deepSet_)(bundleClone, ['unit', 'input', name, 'data'], (0, evaluateDataValue_1.evaluateData)(data, specs, this.__system.classes));
        const NewBundle = (0, fromUnitBundle_1.fromUnitBundle)(bundleClone, specs, this.__system.classes);
        done({ unit: NewBundle });
    }
}
exports.default = SetInput;
//# sourceMappingURL=index.js.map