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 DeleteMediaTypeCommand = /** @class */ (function (_super) {
    __extends(DeleteMediaTypeCommand, _super);
    function DeleteMediaTypeCommand(mediaType) {
        var _this = this;
        if (((mediaType != null && mediaType instanceof Oas30MediaType) || mediaType === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._mediaTypeName === undefined)
                _this._mediaTypeName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldMediaType === undefined)
                _this._oldMediaType = null;
            if (_this._mediaTypeName === undefined)
                _this._mediaTypeName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldMediaType === undefined)
                _this._oldMediaType = null;
            (function () {
                _this._mediaTypeName = mediaType.getName();
                _this._mediaTypePath = Library.createNodePath(mediaType);
                _this._parentPath = Library.createNodePath(mediaType.parent());
            })();
        }
        else if (mediaType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._mediaTypeName === undefined)
                _this._mediaTypeName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldMediaType === undefined)
                _this._oldMediaType = null;
            if (_this._mediaTypeName === undefined)
                _this._mediaTypeName = null;
            if (_this._mediaTypePath === undefined)
                _this._mediaTypePath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldMediaType === undefined)
                _this._oldMediaType = 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
     */
    DeleteMediaTypeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteMediaTypeCommand] Executing.");
        this._oldMediaType = null;
        var mediaType = this._mediaTypePath.resolve(document);
        if (this.isNullOrUndefined(mediaType)) {
            return;
        }
        var parent = mediaType.parent();
        parent.removeMediaType(this._mediaTypeName);
        this._oldMediaType = Library.writeNode(mediaType);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteMediaTypeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteMediaTypeCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldMediaType)) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var mediaType = parent.createMediaType(this._mediaTypeName);
        Library.readNode(this._oldMediaType, mediaType);
        parent.addMediaType(this._mediaTypeName, mediaType);
    };
    return DeleteMediaTypeCommand;
}(AbstractCommand));
export { DeleteMediaTypeCommand };
DeleteMediaTypeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteMediaTypeCommand";
DeleteMediaTypeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteMediaTypeCommand.js.map