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 { Oas30Example } from '../../openapi/v3/models/Oas30Example';
/**
 * A command used to delete a single example.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteExampleCommand_30 = /** @class */ (function (_super) {
    __extends(DeleteExampleCommand_30, _super);
    function DeleteExampleCommand_30(example) {
        var _this = this;
        if (((example != null && example instanceof Oas30Example) || example === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._exampleName === undefined)
                _this._exampleName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            if (_this._exampleName === undefined)
                _this._exampleName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            (function () {
                _this._exampleName = example.getName();
                _this._mediaTypePath = Library.createNodePath(example.parent());
            })();
        }
        else if (example === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._exampleName === undefined)
                _this._exampleName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            if (_this._exampleName === undefined)
                _this._exampleName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = 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_30.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteExampleCommand] Executing.");
        this._oldExample = null;
        var mediaType = this._mediaTypePath.resolve(document);
        if (this.isNullOrUndefined(mediaType) || this.isNullOrUndefined(mediaType.getExample(this._exampleName))) {
            LoggerCompat.debug("[DeleteExampleCommand] No example named: " + this._exampleName);
            return;
        }
        var example = mediaType.removeExample(this._exampleName);
        this._oldExample = Library.writeNode(example);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteExampleCommand_30.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteExampleCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldExample)) {
            return;
        }
        var mediaType = this._mediaTypePath.resolve(document);
        if (this.isNullOrUndefined(mediaType)) {
            LoggerCompat.info("[DeleteExampleCommand] No media type found.");
            return;
        }
        var example = mediaType.createExample(this._exampleName);
        Library.readNode(this._oldExample, example);
        mediaType.addExample(example);
    };
    return DeleteExampleCommand_30;
}(AbstractCommand));
export { DeleteExampleCommand_30 };
DeleteExampleCommand_30["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteExampleCommand_30";
DeleteExampleCommand_30["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteExampleCommand_30.js.map