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 { CombinedVisitorAdapter } from '../../combined/visitors/CombinedVisitorAdapter';
import { LoggerCompat } from '../../compat/LoggerCompat';
import { OasSchema } from '../../openapi/models/OasSchema';
import { AbstractSchemaInhCommand } from './AbstractSchemaInhCommand';
/**
 * A command used to delete a single child schema from a parent schema.
 * @author eric.wittmann@gmail.com
 * @extends AbstractSchemaInhCommand
 * @class
 */
var DeleteChildSchemaCommand = /** @class */ (function (_super) {
    __extends(DeleteChildSchemaCommand, _super);
    function DeleteChildSchemaCommand(schema) {
        var _this = this;
        if (((schema != null && schema instanceof OasSchema) || schema === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            if (_this._oldSchemaType === undefined)
                _this._oldSchemaType = null;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            if (_this._oldSchemaType === undefined)
                _this._oldSchemaType = null;
            (function () {
                _this._schemaPath = Library.createNodePath(schema);
                _this._parentPath = Library.createNodePath(schema.parent());
            })();
        }
        else if (schema === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            if (_this._oldSchemaType === undefined)
                _this._oldSchemaType = null;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._parentPath === undefined)
                _this._parentPath = null;
            if (_this._oldSchema === undefined)
                _this._oldSchema = null;
            if (_this._oldSchemaType === undefined)
                _this._oldSchemaType = 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
     */
    DeleteChildSchemaCommand.prototype.execute = function (document) {
        LoggerCompat.info("[DeleteChildSchemaCommand] Executing.");
        this._oldSchema = null;
        var childSchema = this._schemaPath.resolve(document);
        if (this.isNullOrUndefined(childSchema)) {
            return;
        }
        var schemaRemover = new DeleteChildSchemaCommand.SchemaRemoverVisitor();
        Library.visitNode(childSchema, schemaRemover);
        this._oldSchema = Library.writeNode(childSchema);
        this._oldSchemaType = schemaRemover.type;
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteChildSchemaCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteChildSchemaCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldSchema)) {
            return;
        }
        var parent = this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        var schema = this.createSchema(parent, this._oldSchemaType);
        Library.readNode(this._oldSchema, schema);
        var schemaAdder = new DeleteChildSchemaCommand.SchemaAdderVisitor();
        Library.visitNode(schema, schemaAdder);
    };
    return DeleteChildSchemaCommand;
}(AbstractSchemaInhCommand));
export { DeleteChildSchemaCommand };
DeleteChildSchemaCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteChildSchemaCommand";
DeleteChildSchemaCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
(function (DeleteChildSchemaCommand) {
    /**
     * Visitor used to remove a child schema from its parent.
     * @author eric.wittmann@gmail.com
     * @extends CombinedVisitorAdapter
     * @class
     */
    var SchemaRemoverVisitor = /** @class */ (function (_super) {
        __extends(SchemaRemoverVisitor, _super);
        function SchemaRemoverVisitor() {
            var _this = _super.call(this) || this;
            if (_this.type === undefined)
                _this.type = null;
            return _this;
        }
        /**
         * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitAllOfSchema(io.apicurio.datamodels.openapi.models.OasSchema)
         * @param {OasSchema} node
         */
        SchemaRemoverVisitor.prototype.visitAllOfSchema = function (node) {
            var parentSchema = node.parent();
            parentSchema.removeAllOfSchema(node);
            this.type = AbstractSchemaInhCommand.TYPE_ALL_OF;
        };
        /**
         * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitAnyOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)
         * @param {Oas30Schema.Oas30AnyOfSchema} node
         */
        SchemaRemoverVisitor.prototype.visitAnyOfSchema = function (node) {
            var parentSchema = node.parent();
            parentSchema.removeAnyOfSchema(node);
            this.type = AbstractSchemaInhCommand.TYPE_ANY_OF;
        };
        /**
         * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitOneOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema)
         * @param {Oas30Schema.Oas30OneOfSchema} node
         */
        SchemaRemoverVisitor.prototype.visitOneOfSchema = function (node) {
            var parentSchema = node.parent();
            parentSchema.removeOneOfSchema(node);
            this.type = AbstractSchemaInhCommand.TYPE_ONE_OF;
        };
        return SchemaRemoverVisitor;
    }(CombinedVisitorAdapter));
    DeleteChildSchemaCommand.SchemaRemoverVisitor = SchemaRemoverVisitor;
    SchemaRemoverVisitor["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteChildSchemaCommand.SchemaRemoverVisitor";
    SchemaRemoverVisitor["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.asyncapi.v2.visitors.IAai20Visitor", "io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor", "io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor", "io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor", "io.apicurio.datamodels.openapi.visitors.IOasVisitor"];
    /**
     * Visitor used to add a child schema to its parent.
     * @author eric.wittmann@gmail.com
     * @extends CombinedVisitorAdapter
     * @class
     */
    var SchemaAdderVisitor = /** @class */ (function (_super) {
        __extends(SchemaAdderVisitor, _super);
        function SchemaAdderVisitor() {
            return _super.call(this) || this;
        }
        /**
         * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitAllOfSchema(io.apicurio.datamodels.openapi.models.OasSchema)
         * @param {OasSchema} node
         */
        SchemaAdderVisitor.prototype.visitAllOfSchema = function (node) {
            var parentSchema = node.parent();
            parentSchema.addAllOfSchema(node);
        };
        /**
         * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitAnyOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)
         * @param {Oas30Schema.Oas30AnyOfSchema} node
         */
        SchemaAdderVisitor.prototype.visitAnyOfSchema = function (node) {
            var parentSchema = node.parent();
            parentSchema.addAnyOfSchema(node);
        };
        /**
         * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitOneOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema)
         * @param {Oas30Schema.Oas30OneOfSchema} node
         */
        SchemaAdderVisitor.prototype.visitOneOfSchema = function (node) {
            var parentSchema = node.parent();
            parentSchema.addOneOfSchema(node);
        };
        return SchemaAdderVisitor;
    }(CombinedVisitorAdapter));
    DeleteChildSchemaCommand.SchemaAdderVisitor = SchemaAdderVisitor;
    SchemaAdderVisitor["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteChildSchemaCommand.SchemaAdderVisitor";
    SchemaAdderVisitor["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.asyncapi.v2.visitors.IAai20Visitor", "io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor", "io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor", "io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor", "io.apicurio.datamodels.openapi.visitors.IOasVisitor"];
})(DeleteChildSchemaCommand || (DeleteChildSchemaCommand = {}));
//# sourceMappingURL=DeleteChildSchemaCommand.js.map