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 { SimplifiedType } from '../models/SimplifiedType';
import { SimplifiedTypeUtil } from '../util/SimplifiedTypeUtil';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { OasSchema } from '../../openapi/models/OasSchema';
/**
 * A command used to modify the type of a schema.
 * @author eric.wittmann@gmail.com
 * @extends AbstractCommand
 * @class
 */
var ChangeSchemaTypeCommand = /** @class */ (function (_super) {
    __extends(ChangeSchemaTypeCommand, _super);
    function ChangeSchemaTypeCommand(schema, newType) {
        var _this = this;
        if (((schema != null && schema instanceof OasSchema) || schema === null) && ((newType != null && newType instanceof SimplifiedType) || newType === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldType === undefined)
                _this._oldType = null;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldType === undefined)
                _this._oldType = null;
            (function () {
                _this._schemaPath = Library.createNodePath(schema);
                _this._newType = newType;
            })();
        }
        else if (schema === undefined && newType === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldType === undefined)
                _this._oldType = null;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._newType === undefined)
                _this._newType = null;
            if (_this._oldType === undefined)
                _this._oldType = 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
     */
    ChangeSchemaTypeCommand.prototype.execute = function (document) {
        LoggerCompat.info("[ChangeSchemaTypeCommand] Executing: " + this._newType);
        this._oldType = null;
        var schema = this._schemaPath.resolve(document);
        if (this.isNullOrUndefined(schema)) {
            return;
        }
        this._oldType = SimplifiedType.fromSchema(schema);
        SimplifiedTypeUtil.setSimplifiedType(schema, this._newType);
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    ChangeSchemaTypeCommand.prototype.undo = function (document) {
        LoggerCompat.info("[ChangeSchemaTypeCommand] Reverting.");
        if (this._oldType == null) {
            return;
        }
        var schema = this._schemaPath.resolve(document);
        if (this.isNullOrUndefined(schema)) {
            return;
        }
        SimplifiedTypeUtil.setSimplifiedType(schema, this._oldType);
    };
    return ChangeSchemaTypeCommand;
}(AbstractCommand));
export { ChangeSchemaTypeCommand };
ChangeSchemaTypeCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ChangeSchemaTypeCommand";
ChangeSchemaTypeCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ChangeSchemaTypeCommand.js.map