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 operation in a path.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var NewOperationCommand = /** @class */ (function (_super) {
    __extends(NewOperationCommand, _super);
    function NewOperationCommand(path, method) {
        var _this = this;
        if (((typeof path === 'string') || path === null) && ((typeof method === 'string') || method === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._created === undefined)
                _this._created = false;
            (function () {
                _this._path = path;
                _this._method = method;
            })();
        }
        else if (path === undefined && method === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._method === undefined)
                _this._method = 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
     */
    NewOperationCommand.prototype.execute = function (document) {
        LoggerCompat.info("[NewOperationCommand] Executing.");
        var odoc = document;
        this._created = false;
        if (this.isNullOrUndefined(odoc.paths)) {
            return;
        }
        var path = odoc.paths.getPathItem(this._path);
        if (this.isNullOrUndefined(path)) {
            return;
        }
        var operation = path.createOperation(this._method);
        NodeCompat.setProperty(path, this._method, operation);
        this._created = true;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewOperationCommand.prototype.undo = function (document) {
        LoggerCompat.info("[NewOperationCommand] Reverting.");
        if (!this._created) {
            return;
        }
        var odoc = document;
        if (this.isNullOrUndefined(odoc.paths)) {
            return;
        }
        var path = odoc.paths.getPathItem(this._path);
        if (this.isNullOrUndefined(path)) {
            return;
        }
        NodeCompat.setProperty(path, this._method, null);
    };
    return NewOperationCommand;
}(AbstractCommand));
export { NewOperationCommand };
NewOperationCommand["__class"] = "io.apicurio.datamodels.cmd.commands.NewOperationCommand";
NewOperationCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewOperationCommand.js.map