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';
/**
 * A command used to add a new pathItem in a document.  Source for the new
 * pathItem must be provided.  This source will be converted to an OAS
 * pathItem object and then added to the data model.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var AddPathItemCommand = /** @class */ (function (_super) {
    __extends(AddPathItemCommand, _super);
    function AddPathItemCommand(pathItemName, from) {
        var _this = this;
        if (((typeof pathItemName === 'string') || pathItemName === null) && ((from != null) || from === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._pathItemExists === undefined)
                _this._pathItemExists = false;
            if (_this._newPathItemName === undefined)
                _this._newPathItemName = null;
            if (_this._newPathItemObj === undefined)
                _this._newPathItemObj = null;
            if (_this._nullPathItems === undefined)
                _this._nullPathItems = false;
            if (_this._pathItemExists === undefined)
                _this._pathItemExists = false;
            if (_this._newPathItemName === undefined)
                _this._newPathItemName = null;
            if (_this._newPathItemObj === undefined)
                _this._newPathItemObj = null;
            if (_this._nullPathItems === undefined)
                _this._nullPathItems = false;
            (function () {
                _this._newPathItemName = pathItemName;
                _this._newPathItemObj = from;
            })();
        }
        else if (((typeof pathItemName === 'string') || pathItemName === null) && from === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._pathItemExists === undefined)
                _this._pathItemExists = false;
            if (_this._newPathItemName === undefined)
                _this._newPathItemName = null;
            if (_this._newPathItemObj === undefined)
                _this._newPathItemObj = null;
            if (_this._nullPathItems === undefined)
                _this._nullPathItems = false;
            if (_this._pathItemExists === undefined)
                _this._pathItemExists = false;
            if (_this._newPathItemName === undefined)
                _this._newPathItemName = null;
            if (_this._newPathItemObj === undefined)
                _this._newPathItemObj = null;
            if (_this._nullPathItems === undefined)
                _this._nullPathItems = false;
            (function () {
                _this._newPathItemName = pathItemName;
            })();
        }
        else if (pathItemName === undefined && from === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._pathItemExists === undefined)
                _this._pathItemExists = false;
            if (_this._newPathItemName === undefined)
                _this._newPathItemName = null;
            if (_this._newPathItemObj === undefined)
                _this._newPathItemObj = null;
            if (_this._nullPathItems === undefined)
                _this._nullPathItems = false;
            if (_this._pathItemExists === undefined)
                _this._pathItemExists = false;
            if (_this._newPathItemName === undefined)
                _this._newPathItemName = null;
            if (_this._newPathItemObj === undefined)
                _this._newPathItemObj = null;
            if (_this._nullPathItems === undefined)
                _this._nullPathItems = 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
     */
    AddPathItemCommand.prototype.execute = function (document) {
        LoggerCompat.info("[AddPathItemCommand] Executing.");
        var doc = document;
        if (this.isNullOrUndefined(doc.paths)) {
            doc.paths = doc.createPaths();
            this._nullPathItems = true;
        }
        if (!this.isNullOrUndefined(doc.paths.getPathItem(this._newPathItemName))) {
            LoggerCompat.info("[AddPathItemCommand] PathItem with name %s already exists.", this._newPathItemName);
            this._pathItemExists = true;
        }
        else {
            var pathItem = doc.paths.createPathItem(this._newPathItemName);
            Library.readNode(this._newPathItemObj, pathItem);
            doc.paths.addPathItem(this._newPathItemName, pathItem);
            this._pathItemExists = false;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    AddPathItemCommand.prototype.undo = function (document) {
        LoggerCompat.info("[AddPathItemCommand] Reverting.");
        if (this._pathItemExists) {
            return;
        }
        var doc = document;
        if (this._nullPathItems) {
            doc.paths = null;
        }
        else {
            doc.paths.removePathItem(this._newPathItemName);
        }
    };
    return AddPathItemCommand;
}(AbstractCommand));
export { AddPathItemCommand };
AddPathItemCommand["__class"] = "io.apicurio.datamodels.cmd.commands.AddPathItemCommand";
AddPathItemCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=AddPathItemCommand.js.map