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 { Oas20Response } from '../../openapi/v2/models/Oas20Response';
/**
 * A command used to delete a single example.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteExampleCommand_20 = /** @class */ (function (_super) {
    __extends(DeleteExampleCommand_20, _super);
    function DeleteExampleCommand_20(response, contentType) {
        var _this = this;
        if (((response != null && response instanceof Oas20Response) || response === null) && ((typeof contentType === 'string') || contentType === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._exampleContentType === undefined)
                _this._exampleContentType = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            if (_this._exampleContentType === undefined)
                _this._exampleContentType = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            (function () {
                _this._responsePath = Library.createNodePath(response);
                _this._exampleContentType = contentType;
            })();
        }
        else if (response === undefined && contentType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._exampleContentType === undefined)
                _this._exampleContentType = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            if (_this._exampleContentType === undefined)
                _this._exampleContentType = null;
            if (_this._responsePath === undefined)
                _this._responsePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = 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
     */
    DeleteExampleCommand_20.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteExampleCommand] Executing.");
        this._oldExample = null;
        var response = this._responsePath.resolve(document);
        if (this.isNullOrUndefined(response) || this.isNullOrUndefined(response.examples) || this.isNullOrUndefined(response.examples.getExample(this._exampleContentType))) {
            LoggerCompat.debug("[DeleteExampleCommand] No example with content-type: " + this._exampleContentType);
            return;
        }
        this._oldExample = response.examples.removeExample(this._exampleContentType);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteExampleCommand_20.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteExampleCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldExample)) {
            return;
        }
        var response = this._responsePath.resolve(document);
        if (this.isNullOrUndefined(response)) {
            return;
        }
        if (this.isNullOrUndefined(response.examples)) {
            response.examples = response.createExample();
        }
        response.examples.addExample(this._exampleContentType, this._oldExample);
    };
    return DeleteExampleCommand_20;
}(AbstractCommand));
export { DeleteExampleCommand_20 };
DeleteExampleCommand_20["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteExampleCommand_20";
DeleteExampleCommand_20["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteExampleCommand_20.js.map