"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var object_1 = require("../changes/object");
var field_1 = require("../changes/field");
var field_2 = require("./field");
var arrays_1 = require("../utils/arrays");
function changesInObject(oldType, newType) {
    var changes = [];
    // Interfaces
    changes.push.apply(changes, addedInterfaces(oldType, newType));
    changes.push.apply(changes, removedInterfaces(oldType, newType));
    // Fields
    changes.push.apply(changes, addedFields(oldType, newType));
    changes.push.apply(changes, removedFields(oldType, newType));
    changedFields(oldType, newType).forEach(function (_a) {
        var inOld = _a.inOld, inNew = _a.inNew;
        changes.push.apply(changes, field_2.changesInField(oldType, inOld, inNew));
    });
    return changes;
}
exports.changesInObject = changesInObject;
function addedInterfaces(oldType, newType) {
    var oldInterfaces = oldType.getInterfaces();
    var newInterfaces = newType.getInterfaces();
    var oldNames = oldInterfaces.map(function (i) { return i.name; });
    var newNames = newInterfaces.map(function (i) { return i.name; });
    return arrays_1.diffArrays(newNames, oldNames)
        .map(function (name) { return newInterfaces.find(function (i) { return i.name === name; }); })
        .map(function (i) { return object_1.objectTypeInterfaceAdded(i, newType); });
}
function removedInterfaces(oldType, newType) {
    var oldInterfaces = oldType.getInterfaces();
    var newInterfaces = newType.getInterfaces();
    var oldNames = oldInterfaces.map(function (i) { return i.name; });
    var newNames = newInterfaces.map(function (i) { return i.name; });
    return arrays_1.diffArrays(oldNames, newNames)
        .map(function (name) { return oldInterfaces.find(function (i) { return i.name === name; }); })
        .map(function (i) { return object_1.objectTypeInterfaceRemoved(i, newType); });
}
function addedFields(oldType, newType) {
    var oldFields = oldType.getFields();
    var newFields = newType.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(newType, f); });
}
function removedFields(oldType, newType) {
    var oldFields = oldType.getFields();
    var newFields = newType.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(oldType, f); });
}
function changedFields(oldType, newType) {
    var oldFields = oldType.getFields();
    var newFields = newType.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=object.js.map