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