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 { LoggerCompat } from '../../compat/LoggerCompat';
import { Oas20Response } from '../../openapi/v2/models/Oas20Response';
import { SetExampleCommand } from './SetExampleCommand';
/**
 * @author eric.wittmann@gmail.com
 * @extends SetExampleCommand
 * @class
 */
var SetExampleCommand_20 = /** @class */ (function (_super) {
    __extends(SetExampleCommand_20, _super);
    function SetExampleCommand_20(parent, example, contentType) {
        var _this = this;
        if (((parent != null && parent instanceof Oas20Response) || parent === null) && ((example != null) || example === null) && ((typeof contentType === 'string') || contentType === null)) {
            var __args = arguments;
            _this = _super.call(this, parent, example) || this;
            if (_this._newContentType === undefined)
                _this._newContentType = null;
            if (_this._nullExamples === undefined)
                _this._nullExamples = false;
            if (_this._newContentType === undefined)
                _this._newContentType = null;
            if (_this._nullExamples === undefined)
                _this._nullExamples = false;
            (function () {
                _this._newContentType = contentType;
            })();
        }
        else if (parent === undefined && example === undefined && contentType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._newContentType === undefined)
                _this._newContentType = null;
            if (_this._nullExamples === undefined)
                _this._nullExamples = false;
            if (_this._newContentType === undefined)
                _this._newContentType = null;
            if (_this._nullExamples === undefined)
                _this._nullExamples = 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
     */
    SetExampleCommand_20.prototype.execute = function (document) {
        LoggerCompat.info("[SetExampleCommand_20] Executing.");
        this._oldValue = null;
        var response = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(response)) {
            return;
        }
        if (this.isNullOrUndefined(response.examples)) {
            response.examples = response.createExample();
            this._nullExamples = true;
        }
        this._oldValue = response.examples.getExample(this._newContentType);
        response.examples.addExample(this._newContentType, this._newExample);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    SetExampleCommand_20.prototype.undo = function (document) {
        LoggerCompat.info("[SetExampleCommand_20] Reverting.");
        var response = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(response)) {
            return;
        }
        if (this.isNullOrUndefined(response.examples)) {
            return;
        }
        if (this._nullExamples) {
            response.examples = null;
            return;
        }
        if (this.isNullOrUndefined(this._oldValue)) {
            response.examples.removeExample(this._newContentType);
        }
        else {
            response.examples.addExample(this._newContentType, this._oldValue);
        }
    };
    return SetExampleCommand_20;
}(SetExampleCommand));
export { SetExampleCommand_20 };
SetExampleCommand_20["__class"] = "io.apicurio.datamodels.cmd.commands.SetExampleCommand_20";
SetExampleCommand_20["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=SetExampleCommand_20.js.map