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 delete a single parameter from an operation.
 * @author laurent.broudoux@gmail.com
 * @extends AbstractCommand
 * @class
 */
var DeleteAllParameterExamplesCommand = /** @class */ (function (_super) {
    __extends(DeleteAllParameterExamplesCommand, _super);
    function DeleteAllParameterExamplesCommand(parameter) {
        var _this = this;
        if (((parameter != null && parameter instanceof Oas30Parameter) || parameter === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExamples === undefined)
                _this._oldExamples = null;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExamples === undefined)
                _this._oldExamples = null;
            (function () {
                _this._parameterPath = Library.createNodePath(parameter);
            })();
        }
        else if (parameter === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExamples === undefined)
                _this._oldExamples = null;
            if (_this._parameterPath === undefined)
                _this._parameterPath = null;
            if (_this._oldExamples === undefined)
                _this._oldExamples = 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
     */
    DeleteAllParameterExamplesCommand.prototype.execute = function (document) {
        var _this = this;
        LoggerCompat.info("[DeleteAllParameterExamplesCommand] Executing.");
        if (this.isNullOrUndefined(document)) {
            LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not execute the command, invalid argument.");
            return;
        }
        if (this.isNullOrUndefined(this._parameterPath)) {
            LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not execute the command, problem when unmarshalling.");
            return;
        }
        var parameter = this._parameterPath.resolve(document);
        if (this.isNullOrUndefined(parameter)) {
            LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Parameter not found.");
            return;
        }
        this._oldExamples = ({});
        parameter.getExamples().forEach(function (e) {
            /* put */ (_this._oldExamples[e.getName()] = Library.writeNode(e));
        });
        parameter.examples = ({});
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllParameterExamplesCommand.prototype.undo = function (document) {
        if (this.isNullOrUndefined(document)) {
            LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not revert the command, invalid argument.");
            return;
        }
        if (this.isNullOrUndefined(this._parameterPath)) {
            LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not revert the command, problem when unmarshalling.");
            return;
        }
        LoggerCompat.info("[DeleteAllParameterExamplesCommand] Reverting.");
        var parameter = this._parameterPath.resolve(document);
        if (this.isNullOrUndefined(parameter)) {
            LoggerCompat.info("[DeleteAllParameterExamplesCommand] No parameter found.");
            return;
        }
        if (this.isNullOrUndefined(this._oldExamples)) {
            LoggerCompat.info("[DeleteAllExamplesCommand] Could not revert. Previous data is not available.");
            return;
        }
        {
            var array228 = /* keySet */ Object.keys(this._oldExamples);
            for (var index227 = 0; index227 < array228.length; index227++) {
                var k = array228[index227];
                {
                    var example = parameter.createExample(k);
                    Library.readNode(/* get */ (function (m, k) { return m[k] === undefined ? null : m[k]; })(this._oldExamples, k), example);
                    parameter.addExample(example);
                }
            }
        }
    };
    return DeleteAllParameterExamplesCommand;
}(AbstractCommand));
export { DeleteAllParameterExamplesCommand };
DeleteAllParameterExamplesCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteAllParameterExamplesCommand";
DeleteAllParameterExamplesCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteAllParameterExamplesCommand.js.map