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 { NodeCompat } from '../../compat/NodeCompat';
import { Document } from '../../core/models/Document';
import { OasOperation } from '../../openapi/models/OasOperation';
import { ReplaceNodeCommand } from './ReplaceNodeCommand';
/**
 * A command used to replace an operation with a newer version.
 * @author eric.wittmann@gmail.com
 * @extends ReplaceNodeCommand
 * @class
 */
var ReplaceOperationCommand = /** @class */ (function (_super) {
    __extends(ReplaceOperationCommand, _super);
    function ReplaceOperationCommand(old, replacement) {
        var _this = this;
        if (((old != null && old instanceof OasOperation) || old === null) && ((replacement != null && replacement instanceof OasOperation) || replacement === null)) {
            var __args = arguments;
            _this = _super.call(this, old, replacement) || this;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._path === undefined)
                _this._path = null;
            (function () {
                _this._method = old.getMethod();
                _this._path = old.parent().getPath();
            })();
        }
        else if (old === undefined && replacement === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._path === undefined)
                _this._path = null;
            if (_this._method === undefined)
                _this._method = null;
            if (_this._path === undefined)
                _this._path = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    ReplaceOperationCommand.prototype.removeNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_openapi_models_OasOperation = function (doc, node) {
        var odoc = doc;
        var path = odoc.paths.getPathItem(this._path);
        NodeCompat.setProperty(path, node.getMethod(), null);
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#removeNode(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.Node)
     * @param {Document} doc
     * @param {OasOperation} node
     */
    ReplaceOperationCommand.prototype.removeNode = function (doc, node) {
        if (((doc != null && doc instanceof Document) || doc === null) && ((node != null && node instanceof OasOperation) || node === null)) {
            return this.removeNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_openapi_models_OasOperation(doc, node);
        }
        else if (((doc != null && doc instanceof Document) || doc === null) && ((node != null) || node === null)) {
            throw new Error('cannot invoke abstract overloaded method... check your argument(s) type(s)');
        }
        else
            throw new Error('invalid overload');
    };
    ReplaceOperationCommand.prototype.addNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_openapi_models_OasOperation = function (doc, node) {
        var odoc = doc;
        var path = odoc.paths.getPathItem(this._path);
        node._parent = path;
        node._ownerDocument = path.ownerDocument();
        NodeCompat.setProperty(path, node.getMethod(), node);
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#addNode(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.Node)
     * @param {Document} doc
     * @param {OasOperation} node
     */
    ReplaceOperationCommand.prototype.addNode = function (doc, node) {
        if (((doc != null && doc instanceof Document) || doc === null) && ((node != null && node instanceof OasOperation) || node === null)) {
            return this.addNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_openapi_models_OasOperation(doc, node);
        }
        else if (((doc != null && doc instanceof Document) || doc === null) && ((node != null) || node === null)) {
            throw new Error('cannot invoke abstract overloaded method... check your argument(s) type(s)');
        }
        else
            throw new Error('invalid overload');
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#readNode(io.apicurio.datamodels.core.models.Document, java.lang.Object)
     * @param {Document} doc
     * @param {*} node
     * @return {OasOperation}
     */
    ReplaceOperationCommand.prototype.readNode = function (doc, node) {
        var odoc = doc;
        var parent = odoc.paths.getPathItem(this._path);
        var operation = parent.createOperation(this._method);
        Library.readNode(node, operation);
        return operation;
    };
    return ReplaceOperationCommand;
}(ReplaceNodeCommand));
export { ReplaceOperationCommand };
ReplaceOperationCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ReplaceOperationCommand";
ReplaceOperationCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ReplaceOperationCommand.js.map