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 { ModelUtils } from '../util/ModelUtils';
import { LoggerCompat } from '../../compat/LoggerCompat';
/**
 * A command used to create a new media type.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var NewMediaTypeCommand = /** @class */ (function (_super) {
    __extends(NewMediaTypeCommand, _super);
    function NewMediaTypeCommand(parent, newMediaType) {
        var _this = this;
        if (((parent != null && (parent["__interfaces"] != null && parent["__interfaces"].indexOf("io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent") >= 0 || parent.constructor != null && parent.constructor["__interfaces"] != null && parent.constructor["__interfaces"].indexOf("io.apicurio.datamodels.openapi.v3.models.IOas30MediaTypeParent") >= 0)) || parent === null) && ((typeof newMediaType === 'string') || newMediaType === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._newMediaType === undefined)
                _this._newMediaType = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._newMediaType === undefined)
                _this._newMediaType = null;
            if (_this._created === undefined)
                _this._created = false;
            (function () {
                _this._nodePath = Library.createNodePath(parent);
                _this._newMediaType = newMediaType;
            })();
        }
        else if (parent === undefined && newMediaType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._newMediaType === undefined)
                _this._newMediaType = null;
            if (_this._created === undefined)
                _this._created = false;
            if (_this._nodePath === undefined)
                _this._nodePath = null;
            if (_this._newMediaType === undefined)
                _this._newMediaType = null;
            if (_this._created === undefined)
                _this._created = 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
     */
    NewMediaTypeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[NewMediaTypeCommand] Executing.");
        this._created = false;
        var node = this._nodePath.resolve(document);
        if (this.isNullOrUndefined(node)) {
            return;
        }
        var mediaType = node.getMediaType(this._newMediaType);
        if (ModelUtils.isDefined(mediaType)) {
            return;
        }
        node.addMediaType(this._newMediaType, node.createMediaType(this._newMediaType));
        this._created = true;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    NewMediaTypeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[NewMediaTypeCommand] Reverting.");
        if (!this._created) {
            LoggerCompat.info("[NewMediaTypeCommand] media type already existed, nothing done so no rollback necessary.");
            return;
        }
        var node = this._nodePath.resolve(document);
        if (this.isNullOrUndefined(node)) {
            return;
        }
        node.removeMediaType(this._newMediaType);
    };
    return NewMediaTypeCommand;
}(AbstractCommand));
export { NewMediaTypeCommand };
NewMediaTypeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.NewMediaTypeCommand";
NewMediaTypeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=NewMediaTypeCommand.js.map