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';
import { OasResponse } from '../../openapi/models/OasResponse';
/**
 * A command used to delete a single response from an operation.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteResponseCommand = /** @class */ (function (_super) {
    __extends(DeleteResponseCommand, _super);
    function DeleteResponseCommand(response) {
        var _this = this;
        if (((response != null && response instanceof OasResponse) || response === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._responseCode === undefined)
                _this._responseCode = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._responsesPath === undefined)
                _this._responsesPath = null;
            if (_this._oldResponse === undefined)
                _this._oldResponse = null;
            if (_this._responseCode === undefined)
                _this._responseCode = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._responsesPath === undefined)
                _this._responsesPath = null;
            if (_this._oldResponse === undefined)
                _this._oldResponse = null;
            (function () {
                _this._responseCode = response.getStatusCode();
                _this._responsePath = Library.createNodePath(response);
                _this._responsesPath = Library.createNodePath(response.parent());
            })();
        }
        else if (response === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._responseCode === undefined)
                _this._responseCode = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._responsesPath === undefined)
                _this._responsesPath = null;
            if (_this._oldResponse === undefined)
                _this._oldResponse = null;
            if (_this._responseCode === undefined)
                _this._responseCode = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._responsesPath === undefined)
                _this._responsesPath = null;
            if (_this._oldResponse === undefined)
                _this._oldResponse = null;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteResponseCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteResponseCommand] Executing.");
        this._oldResponse = null;
        var response = this._responsePath.resolve(document);
        if (this.isNullOrUndefined(response)) {
            return;
        }
        var responses = response.parent();
        if (this.isNullOrUndefined(this._responseCode)) {
            responses.default_ = null;
        }
        else {
            responses.removeResponse(this._responseCode);
        }
        this._oldResponse = Library.writeNode(response);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteResponseCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteResponseCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldResponse)) {
            return;
        }
        var responses = this._responsesPath.resolve(document);
        if (this.isNullOrUndefined(responses)) {
            return;
        }
        var response = responses.createResponse(this._responseCode);
        Library.readNode(this._oldResponse, response);
        if (this.isNullOrUndefined(this._responseCode)) {
            responses.default_ = response;
        }
        else {
            responses.addResponse(this._responseCode, response);
        }
    };
    return DeleteResponseCommand;
}(AbstractCommand));
export { DeleteResponseCommand };
DeleteResponseCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteResponseCommand";
DeleteResponseCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteResponseCommand.js.map