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';
/**
 * A command used to create a new path item in a document.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var NewPathCommand = /** @class */ (function (_super) {
    __extends(NewPathCommand, _super);
    function NewPathCommand(newPath) {
        var _this = this;
        if (((typeof newPath === 'string') || newPath === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newPath === undefined)
                _this._newPath = null;
            if (_this._pathExisted === undefined)
                _this._pathExisted = false;
            if (_this._nullPaths === undefined)
                _this._nullPaths = false;
            if (_this._newPath === undefined)
                _this._newPath = null;
            if (_this._pathExisted === undefined)
                _this._pathExisted = false;
            if (_this._nullPaths === undefined)
                _this._nullPaths = false;
            (function () {
                _this._newPath = newPath;
            })();
        }
        else if (newPath === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newPath === undefined)
                _this._newPath = null;
            if (_this._pathExisted === undefined)
                _this._pathExisted = false;
            if (_this._nullPaths === undefined)
                _this._nullPaths = false;
            if (_this._newPath === undefined)
                _this._newPath = null;
            if (_this._pathExisted === undefined)
                _this._pathExisted = false;
            if (_this._nullPaths === undefined)
                _this._nullPaths = 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
     */
    NewPathCommand.prototype.execute = function (document) {
        LoggerCompat.info("[NewPathCommand] Executing.");
        var odoc = document;
        if (this.isNullOrUndefined(odoc.paths)) {
            odoc.paths = odoc.createPaths();
            this._nullPaths = true;
        }
        if (this.isNullOrUndefined(odoc.paths.getPathItem(this._newPath))) {
            var pathItem = odoc.paths.createPathItem(this._newPath);
            odoc.paths.addPathItem(this._newPath, pathItem);
            this._pathExisted = false;
        }
        else {
            this._pathExisted = true;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewPathCommand.prototype.undo = function (document) {
        LoggerCompat.info("[NewPathCommand] Reverting.");
        var odoc = document;
        if (this._pathExisted) {
            LoggerCompat.info("[NewPathCommand] path already existed, nothing done so no rollback necessary.");
            return;
        }
        if (this._nullPaths) {
            LoggerCompat.info("[NewPathCommand] Paths was null, deleting it.");
            odoc.paths = null;
        }
        else {
            LoggerCompat.info("[NewPathCommand] Removing a path item: %s", this._newPath);
            odoc.paths.removePathItem(this._newPath);
        }
    };
    return NewPathCommand;
}(AbstractCommand));
export { NewPathCommand };
NewPathCommand["__class"] = "io.apicurio.datamodels.cmd.commands.NewPathCommand";
NewPathCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewPathCommand.js.map