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 laurent.broudoux@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteParameterExampleCommand_30 = /** @class */ (function (_super) {
    __extends(DeleteParameterExampleCommand_30, _super);
    function DeleteParameterExampleCommand_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._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            if (_this._exampleName === undefined)
                _this._exampleName = null;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            (function () {
                _this._exampleName = example.getName();
                _this._parameterPath = 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._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExample === undefined)
                _this._oldExample = null;
            if (_this._exampleName === undefined)
                _this._exampleName = null;
            if (_this._parameterPath === undefined)
                _this._parameterPath = 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
     */
    DeleteParameterExampleCommand_30.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteExampleCommand] Executing.");
        this._oldExample = null;
        var parameter = this._parameterPath.resolve(document);
        if (this.isNullOrUndefined(parameter) || this.isNullOrUndefined(parameter.getExample(this._exampleName))) {
            LoggerCompat.debug("[DeleteExampleCommand] No example named: " + this._exampleName);
            return;
        }
        var example = parameter.removeExample(this._exampleName);
        this._oldExample = Library.writeNode(example);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteParameterExampleCommand_30.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteExampleCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldExample)) {
            return;
        }
        var parameter = this._parameterPath.resolve(document);
        if (this.isNullOrUndefined(parameter)) {
            LoggerCompat.info("[DeleteExampleCommand] No parameter found.");
            return;
        }
        var example = parameter.createExample(this._exampleName);
        Library.readNode(this._oldExample, example);
        parameter.addExample(example);
    };
    return DeleteParameterExampleCommand_30;
}(AbstractCommand));
export { DeleteParameterExampleCommand_30 };
DeleteParameterExampleCommand_30["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteParameterExampleCommand_30";
DeleteParameterExampleCommand_30["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteParameterExampleCommand_30.js.map