var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* Generated from Java with JSweet 2.3.7 - http://www.jsweet.org */
import { Library } from '../../Library';
import { AbstractCommand } from '../AbstractCommand';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { NodeCompat } from '../../compat/NodeCompat';
/**
 * A command used to delete a single tag definition from the document.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteTagCommand = /** @class */ (function (_super) {
    __extends(DeleteTagCommand, _super);
    function DeleteTagCommand(tagName) {
        var _this = this;
        if (((typeof tagName === 'string') || tagName === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._oldIndex === undefined)
                _this._oldIndex = 0;
            if (_this._oldTag === undefined)
                _this._oldTag = null;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._oldIndex === undefined)
                _this._oldIndex = 0;
            if (_this._oldTag === undefined)
                _this._oldTag = null;
            (function () {
                _this._tagName = tagName;
            })();
        }
        else if (tagName === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._oldIndex === undefined)
                _this._oldIndex = 0;
            if (_this._oldTag === undefined)
                _this._oldTag = null;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._oldIndex === undefined)
                _this._oldIndex = 0;
            if (_this._oldTag === undefined)
                _this._oldTag = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteTagCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteTagCommand] Executing.");
        if (this.isNullOrUndefined(document.tags)) {
            return;
        }
        var tags = document.tags;
        var tag = null;
        for (var index208 = 0; index208 < tags.length; index208++) {
            var t = tags[index208];
            {
                if (NodeCompat.equals(t.name, this._tagName)) {
                    tag = t;
                }
            }
        }
        this._oldIndex = tags.indexOf(tag);
        /* remove */ tags.splice(this._oldIndex, 1)[0];
        this._oldTag = Library.writeNode(tag);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteTagCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteTagCommand] Reverting.");
        if (this.isNullOrUndefined(document.tags)) {
            document.tags = ([]);
        }
        var tag = document.createTag();
        Library.readNode(this._oldTag, tag);
        if ( /* size */document.tags.length >= this._oldIndex) {
            /* add */ document.tags.splice(this._oldIndex, 0, tag);
        }
        else {
            /* add */ (document.tags.push(tag) > 0);
        }
    };
    return DeleteTagCommand;
}(AbstractCommand));
export { DeleteTagCommand };
DeleteTagCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteTagCommand";
DeleteTagCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteTagCommand.js.map