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 { SimplifiedType } from '../models/SimplifiedType';
import { ModelUtils } from '../util/ModelUtils';
import { SimplifiedTypeUtil } from '../util/SimplifiedTypeUtil';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { Oas20Response } from '../../openapi/v2/models/Oas20Response';
/**
 * A command used to modify the type of a response.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangeResponseTypeCommand = /** @class */ (function (_super) {
    __extends(ChangeResponseTypeCommand, _super);
    function ChangeResponseTypeCommand(response, newType) {
        var _this = this;
        if (((response != null && response instanceof Oas20Response) || response === null) && ((newType != null && newType instanceof SimplifiedType) || newType === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            (function () {
                _this._responsePath = Library.createNodePath(response);
                _this._newType = newType;
            })();
        }
        else if (response === undefined && newType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = 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
     */
    ChangeResponseTypeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangeResponseTypeCommand] Executing.");
        var response = this._responsePath.resolve(document);
        if (this.isNullOrUndefined(response)) {
            return;
        }
        this._oldSchema = null;
        if (ModelUtils.isDefined(response.schema)) {
            this._oldSchema = Library.writeNode(response.schema);
        }
        response.schema = response.createSchema();
        SimplifiedTypeUtil.setSimplifiedType(response.schema, this._newType);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeResponseTypeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangeResponseTypeCommand] Reverting.");
        var response = this._responsePath.resolve(document);
        if (this.isNullOrUndefined(response)) {
            return;
        }
        if (ModelUtils.isDefined(this._oldSchema)) {
            response.schema = response.createSchema();
            Library.readNode(this._oldSchema, response.schema);
        }
        else {
            response.schema = null;
        }
    };
    return ChangeResponseTypeCommand;
}(AbstractCommand));
export { ChangeResponseTypeCommand };
ChangeResponseTypeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeResponseTypeCommand";
ChangeResponseTypeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeResponseTypeCommand.js.map