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