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 { Oas30Parameter } from '../../openapi/v3/models/Oas30Parameter';
/**
 * A command used to add an Example for a 3.0 Parameter.  If an example with the same name
 * already exists, this command does nothing.
 * @author laurent.broudoux@gmail.com
 * @extends AbstractCommand
 * @class
 */
var AddParameterExampleCommand_30 = /** @class */ (function (_super) {
    __extends(AddParameterExampleCommand_30, _super);
    function AddParameterExampleCommand_30(parent, example, exampleName, exampleSummary, exampleDescription) {
        var _this = this;
        if (((parent != null && parent instanceof Oas30Parameter) || parent === null) && ((example != null) || example === null) && ((typeof exampleName === 'string') || exampleName === null) && ((typeof exampleSummary === 'string') || exampleSummary === null) && ((typeof exampleDescription === 'string') || exampleDescription === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._newExampleValue === undefined)
                _this._newExampleValue = null;
            if (_this._newExampleName === undefined)
                _this._newExampleName = null;
            if (_this._newExampleSummary === undefined)
                _this._newExampleSummary = null;
            if (_this._newExampleDescription === undefined)
                _this._newExampleDescription = null;
            if (_this._exampleAdded === undefined)
                _this._exampleAdded = false;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._newExampleValue === undefined)
                _this._newExampleValue = null;
            if (_this._newExampleName === undefined)
                _this._newExampleName = null;
            if (_this._newExampleSummary === undefined)
                _this._newExampleSummary = null;
            if (_this._newExampleDescription === undefined)
                _this._newExampleDescription = null;
            if (_this._exampleAdded === undefined)
                _this._exampleAdded = false;
            (function () {
                _this._parentPath = Library.createNodePath(parent);
                _this._newExampleValue = example;
                _this._newExampleName = exampleName;
                _this._newExampleSummary = exampleSummary;
                _this._newExampleDescription = exampleDescription;
            })();
        }
        else if (((parent != null && parent instanceof Oas30Parameter) || parent === null) && ((example != null) || example === null) && ((typeof exampleName === 'string') || exampleName === null) && exampleSummary === undefined && exampleDescription === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._newExampleValue === undefined)
                _this._newExampleValue = null;
            if (_this._newExampleName === undefined)
                _this._newExampleName = null;
            if (_this._newExampleSummary === undefined)
                _this._newExampleSummary = null;
            if (_this._newExampleDescription === undefined)
                _this._newExampleDescription = null;
            if (_this._exampleAdded === undefined)
                _this._exampleAdded = false;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._newExampleValue === undefined)
                _this._newExampleValue = null;
            if (_this._newExampleName === undefined)
                _this._newExampleName = null;
            if (_this._newExampleSummary === undefined)
                _this._newExampleSummary = null;
            if (_this._newExampleDescription === undefined)
                _this._newExampleDescription = null;
            if (_this._exampleAdded === undefined)
                _this._exampleAdded = false;
            (function () {
                _this._parentPath = Library.createNodePath(parent);
                _this._newExampleValue = example;
                _this._newExampleName = exampleName;
            })();
        }
        else if (parent === undefined && example === undefined && exampleName === undefined && exampleSummary === undefined && exampleDescription === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._newExampleValue === undefined)
                _this._newExampleValue = null;
            if (_this._newExampleName === undefined)
                _this._newExampleName = null;
            if (_this._newExampleSummary === undefined)
                _this._newExampleSummary = null;
            if (_this._newExampleDescription === undefined)
                _this._newExampleDescription = null;
            if (_this._exampleAdded === undefined)
                _this._exampleAdded = false;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._newExampleValue === undefined)
                _this._newExampleValue = null;
            if (_this._newExampleName === undefined)
                _this._newExampleName = null;
            if (_this._newExampleSummary === undefined)
                _this._newExampleSummary = null;
            if (_this._newExampleDescription === undefined)
                _this._newExampleDescription = null;
            if (_this._exampleAdded === undefined)
                _this._exampleAdded = 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
     */
    AddParameterExampleCommand_30.prototype.execute = function (document) {
        LoggerCompat.info("[AddParameterExampleCommand_30] Executing.");
        this._exampleAdded = false;
        var parameter = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parameter)) {
            return;
        }
        if (!this.isNullOrUndefined(parameter.getExample(this._newExampleName))) {
            return;
        }
        var example = parameter.createExample(this._newExampleName);
        example.summary = this._newExampleSummary;
        example.description = this._newExampleDescription;
        example.value = this._newExampleValue;
        parameter.addExample(example);
        this._exampleAdded = true;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    AddParameterExampleCommand_30.prototype.undo = function (document) {
        LoggerCompat.info("[AddParameterExampleCommand_30] Reverting.");
        if (!this._exampleAdded) {
            return;
        }
        var parameter = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parameter) || this.isNullOrUndefined(parameter.examples)) {
            return;
        }
        parameter.removeExample(this._newExampleName);
    };
    return AddParameterExampleCommand_30;
}(AbstractCommand));
export { AddParameterExampleCommand_30 };
AddParameterExampleCommand_30["__class"] = "io.apicurio.datamodels.cmd.commands.AddParameterExampleCommand_30";
AddParameterExampleCommand_30["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=AddParameterExampleCommand_30.js.map