"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../Class/Functional");
const spec_1 = require("../../../../client/spec");
const cloneUnitClass_1 = require("../../../../cloneUnitClass");
const stringify_1 = require("../../../../spec/stringify");
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) {
        var _a;
        const { __bundle } = unit;
        const { unit: { id }, } = __bundle;
        const spec = (0, spec_1.getSpec)((0, weakMerge_1.weakMerge)(this.__system.specs, (_a = __bundle.specs) !== null && _a !== void 0 ? _a : {}), id);
        const { inputs = {} } = spec;
        if (!inputs[name]) {
            done(undefined, 'input not found');
            return;
        }
        const NewBundle = (0, cloneUnitClass_1.cloneUnitBundle)(unit);
        NewBundle.__bundle.unit.input = NewBundle.__bundle.unit.input || {};
        NewBundle.__bundle.unit.input[name] =
            NewBundle.__bundle.unit.input[name] || {};
        NewBundle.__bundle.unit.input[name].data = (0, stringify_1.stringify)(data);
        done({ unit: NewBundle });
    }
}
exports.default = SetInput;
//# sourceMappingURL=index.js.map