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 { AbstractCommand } from '../AbstractCommand';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { NodeCompat } from '../../compat/NodeCompat';
/**
 * A command used to create a new tag.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var NewTagCommand = /** @class */ (function (_super) {
    __extends(NewTagCommand, _super);
    function NewTagCommand(name, description) {
        var _this = this;
        if (((typeof name === 'string') || name === null) && ((typeof description === 'string') || description === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._tagDescription === undefined)
                _this._tagDescription = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._tagDescription === undefined)
                _this._tagDescription = null;
            if (_this._created === undefined)
                _this._created = false;
            (function () {
                _this._tagName = name;
                _this._tagDescription = description;
            })();
        }
        else if (name === undefined && description === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._tagDescription === undefined)
                _this._tagDescription = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._tagName === undefined)
                _this._tagName = null;
            if (_this._tagDescription === undefined)
                _this._tagDescription = null;
            if (_this._created === undefined)
                _this._created = false;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewTagCommand.prototype.execute = function (document) {
        LoggerCompat.info("[NewTagCommand] Executing.");
        this._created = false;
        if (this.isNullOrUndefined(document.tags)) {
            document.tags = ([]);
        }
        var tag = this.findTag(document, this._tagName);
        if (this.isNullOrUndefined(tag)) {
            document.addTag(this._tagName, this._tagDescription);
            this._created = true;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewTagCommand.prototype.undo = function (document) {
        LoggerCompat.info("[NewTagCommand] Reverting.");
        if (!this._created) {
            return;
        }
        var tag = this.findTag(document, this._tagName);
        if (this.isNullOrUndefined(tag)) {
            return;
        }
        /* remove */ document.tags.splice(document.tags.indexOf(tag), 1)[0];
    };
    /**
     * Finds a single tag by its name.  No way to do this but iterate through the
     * tags array.
     * @param {OasDocument} doc
     * @param {string} tagName
     * @return {Tag} {OasTag}
     * @param {Document} doc
     * @param {string} tagName
     * @private
     */
    /*private*/ NewTagCommand.prototype.findTag = function (doc, tagName) {
        for (var index212 = 0; index212 < doc.tags.length; index212++) {
            var dt = doc.tags[index212];
            {
                if (NodeCompat.equals(dt.name, tagName)) {
                    return dt;
                }
            }
        }
        return null;
    };
    return NewTagCommand;
}(AbstractCommand));
export { NewTagCommand };
NewTagCommand["__class"] = "io.apicurio.datamodels.cmd.commands.NewTagCommand";
NewTagCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewTagCommand.js.map