"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var field_1 = require("./changes/field");
var argument_1 = require("./argument");
var arrays_1 = require("../utils/arrays");
function changesInField(type, oldField, newField) {
    var changes = [];
    if (oldField.description !== newField.description) {
        changes.push(field_1.fieldDescriptionChanged(type, oldField, newField));
    }
    if (oldField.deprecationReason !== newField.deprecationReason) {
        changes.push(field_1.fieldDeprecationReasonChanged(type, oldField, newField));
    }
    if (oldField.type.toString() !== newField.type.toString()) {
        changes.push(field_1.fieldTypeChanged(type, oldField, newField));
    }
    var oldArgs = oldField.args;
    var newArgs = newField.args;
    var oldNames = oldArgs.map(function (a) { return a.name; });
    var newNames = newArgs.map(function (a) { return a.name; });
    var added = arrays_1.diffArrays(newNames, oldNames).map(function (name) { return newArgs.find(function (a) { return a.name === name; }); });
    var removed = arrays_1.diffArrays(oldNames, newNames).map(function (name) { return oldArgs.find(function (a) { return a.name === name; }); });
    var common = arrays_1.unionArrays(oldNames, newNames).map(function (name) { return ({
        inOld: oldArgs.find(function (a) { return a.name === name; }),
        inNew: newArgs.find(function (a) { return a.name === name; }),
    }); });
    common.forEach(function (_a) {
        var inOld = _a.inOld, inNew = _a.inNew;
        changes.push.apply(changes, argument_1.changesInArgument(type, oldField, inOld, inNew));
    });
    changes.push.apply(changes, added.map(function (arg) { return field_1.fieldArgumentAdded(type, newField, arg); }));
    changes.push.apply(changes, removed.map(function (arg) { return field_1.fieldArgumentRemoved(type, oldField, arg); }));
    return changes;
}
exports.changesInField = changesInField;
//# sourceMappingURL=field.js.map