"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var field_1 = require("../changes/field");
var field_2 = require("./field");
var arrays_1 = require("../utils/arrays");
function changesInInterface(oldInterface, newInterface) {
    var changes = [];
    changes.push.apply(changes, addedFields(oldInterface, newInterface));
    changes.push.apply(changes, removedFields(oldInterface, newInterface));
    changedFields(oldInterface, newInterface).forEach(function (_a) {
        var inOld = _a.inOld, inNew = _a.inNew;
        changes.push.apply(changes, field_2.changesInField(oldInterface, inOld, inNew));
    });
    return changes;
}
exports.changesInInterface = changesInInterface;
function addedFields(oldInterface, newInterface) {
    var oldFields = oldInterface.getFields();
    var newFields = newInterface.getFields();
    var oldNames = Object.keys(oldFields);
    var newNames = Object.keys(newFields);
    return arrays_1.diffArrays(newNames, oldNames)
        .map(function (name) { return newFields[name]; })
        .map(function (f) { return field_1.fieldAdded(newInterface, f); });
}
function removedFields(oldInterface, newInterface) {
    var oldFields = oldInterface.getFields();
    var newFields = newInterface.getFields();
    var oldNames = Object.keys(oldFields);
    var newNames = Object.keys(newFields);
    return arrays_1.diffArrays(oldNames, newNames)
        .map(function (name) { return oldFields[name]; })
        .map(function (f) { return field_1.fieldRemoved(oldInterface, f); });
}
function changedFields(oldInterface, newInterface) {
    var oldFields = oldInterface.getFields();
    var newFields = newInterface.getFields();
    var oldNames = Object.keys(oldFields);
    var newNames = Object.keys(newFields);
    return arrays_1.unionArrays(oldNames, newNames).map(function (name) { return ({
        inOld: oldFields[name],
        inNew: newFields[name],
    }); });
}
//# sourceMappingURL=interface.js.map