"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var directive_1 = require("../changes/directive");
var arrays_1 = require("../utils/arrays");
function changesInDirective(oldDirective, newDirective) {
    var changes = [];
    if (oldDirective.description !== newDirective.description) {
        changes.push(directive_1.directiveDescriptionChanged(oldDirective, newDirective));
    }
    // locations added
    changes.push.apply(changes, arrays_1.diffArrays(newDirective.locations, oldDirective.locations).map(function (location) {
        return directive_1.directiveLocationAdded(newDirective, location);
    }));
    // locations removed
    changes.push.apply(changes, arrays_1.diffArrays(oldDirective.locations, newDirective.locations).map(function (location) {
        return directive_1.directiveLocationRemoved(oldDirective, location);
    }));
    var oldNames = oldDirective.args.map(function (a) { return a.name; });
    var newNames = newDirective.args.map(function (a) { return a.name; });
    // arguments added
    changes.push.apply(changes, arrays_1.diffArrays(newNames, oldNames).map(function (name) {
        return directive_1.directiveArgumentAdded(newDirective, newDirective.args.find(function (a) { return a.name === name; }));
    }));
    // arguments removed
    changes.push.apply(changes, arrays_1.diffArrays(oldNames, newNames).map(function (name) {
        return directive_1.directiveArgumentRemoved(oldDirective, oldDirective.args.find(function (a) { return a.name === name; }));
    }));
    // common arguments
    arrays_1.unionArrays(oldNames, newNames).forEach(function (name) {
        var oldArg = oldDirective.args.find(function (a) { return a.name === name; });
        var newArg = newDirective.args.find(function (a) { return a.name === name; });
        changes.push.apply(changes, changesInDirectiveArgument(oldDirective, oldArg, newArg));
    });
    return changes;
}
exports.changesInDirective = changesInDirective;
function changesInDirectiveArgument(directive, oldArg, newArg) {
    var changes = [];
    if (oldArg.description !== newArg.description) {
        changes.push(directive_1.directiveArgumentDescriptionChanged(directive, oldArg, newArg));
    }
    if (oldArg.defaultValue !== newArg.defaultValue) {
        changes.push(directive_1.directiveArgumentDefaultValueChanged(directive, oldArg, newArg));
    }
    if (oldArg.type.toString() !== newArg.type.toString()) {
        changes.push(directive_1.directiveArgumentTypeChanged(directive, oldArg, newArg));
    }
    return changes;
}
//# sourceMappingURL=directive.js.map