"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var arrays_1 = require("../utils/arrays");
var input_1 = require("./changes/input");
function changesInInputObject(oldInput, newInput) {
    var changes = [];
    var oldFields = oldInput.getFields();
    var newFields = newInput.getFields();
    var oldNames = Object.keys(oldFields).map(function (name) { return oldFields[name].name; });
    var newNames = Object.keys(newFields).map(function (name) { return newFields[name].name; });
    var added = arrays_1.diffArrays(newNames, oldNames).map(function (name) { return newFields[name]; });
    var removed = arrays_1.diffArrays(oldNames, newNames).map(function (name) { return oldFields[name]; });
    var common = arrays_1.unionArrays(oldNames, newNames).map(function (name) { return ({
        inOld: oldFields[name],
        inNew: newFields[name],
    }); });
    common.forEach(function (_a) {
        var inOld = _a.inOld, inNew = _a.inNew;
        changes.push.apply(changes, changesInInputField(oldInput, inOld, inNew));
    });
    changes.push.apply(changes, added.map(function (field) { return input_1.inputFieldAdded(newInput, field); }));
    changes.push.apply(changes, removed.map(function (field) { return input_1.inputFieldRemoved(oldInput, field); }));
    return changes;
}
exports.changesInInputObject = changesInInputObject;
function changesInInputField(input, oldField, newField) {
    var changes = [];
    if (oldField.description !== newField.description) {
        changes.push(input_1.inputFieldDescriptionChanged(input, oldField, newField));
    }
    if (oldField.defaultValue !== newField.defaultValue) {
        changes.push(input_1.inputFieldDefaultValueChanged(input, oldField, newField));
    }
    if (oldField.type.toString() !== newField.type.toString()) {
        changes.push(input_1.inputFieldTypeChanged(input, oldField, newField));
    }
    // TODO: diff directives
    return changes;
}
//# sourceMappingURL=input.js.map