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 { LoggerCompat } from '../../compat/LoggerCompat';
import { NodeCompat } from '../../compat/NodeCompat';
import { OasSchema } from '../../openapi/models/OasSchema';
import { AbstractSchemaInhCommand } from './AbstractSchemaInhCommand';
/**
 * A command used to delete all child schemas from a schema.
 * @author eric.wittmann@gmail.com
 * @extends AbstractSchemaInhCommand
 * @class
 */
var DeleteAllChildSchemasCommand = /** @class */ (function (_super) {
    __extends(DeleteAllChildSchemasCommand, _super);
    function DeleteAllChildSchemasCommand(parent, type) {
        var _this = this;
        if (((parent != null && parent instanceof OasSchema) || parent === null) && ((typeof type === 'string') || type === null)) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._childSchemaType === undefined)
                _this._childSchemaType = null;
            if (_this._oldSchemas === undefined)
                _this._oldSchemas = null;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._childSchemaType === undefined)
                _this._childSchemaType = null;
            if (_this._oldSchemas === undefined)
                _this._oldSchemas = null;
            (function () {
                _this._schemaPath = Library.createNodePath(parent);
                _this._childSchemaType = type;
            })();
        }
        else if (parent === undefined && type === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._childSchemaType === undefined)
                _this._childSchemaType = null;
            if (_this._oldSchemas === undefined)
                _this._oldSchemas = null;
            if (_this._schemaPath === undefined)
                _this._schemaPath = null;
            if (_this._childSchemaType === undefined)
                _this._childSchemaType = null;
            if (_this._oldSchemas === undefined)
                _this._oldSchemas = 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
     */
    DeleteAllChildSchemasCommand.prototype.execute = function (document) {
        var _this = this;
        LoggerCompat.info("[DeleteAllChildSchemasCommand] Executing.");
        this._oldSchemas = ([]);
        var schema = this._schemaPath.resolve(document);
        if (this.isNullOrUndefined(schema)) {
            return;
        }
        var schemas = ([]);
        if (NodeCompat.equals(AbstractSchemaInhCommand.TYPE_ALL_OF, this._childSchemaType)) {
            schemas = schema.allOf;
            schema.allOf = ([]);
        }
        if (NodeCompat.equals(AbstractSchemaInhCommand.TYPE_ANY_OF, this._childSchemaType)) {
            var schema30 = schema;
            schemas = schema30.anyOf;
            schema30.anyOf = ([]);
        }
        if (NodeCompat.equals(AbstractSchemaInhCommand.TYPE_ONE_OF, this._childSchemaType)) {
            var schema30 = schema;
            schemas = schema30.oneOf;
            schema30.oneOf = ([]);
        }
        if (this.isNullOrUndefined(schemas)) {
            return;
        }
        this._oldSchemas = ([]);
        schemas.forEach(function (oldSchema) {
            /* add */ (_this._oldSchemas.push(Library.writeNode(oldSchema)) > 0);
        });
    };
    /**
     * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
     * @param {Document} document
     */
    DeleteAllChildSchemasCommand.prototype.undo = function (document) {
        LoggerCompat.info("[DeleteAllChildSchemasCommand] Reverting.");
        if (this.isNullOrUndefined(this._oldSchemas) || /* size */ this._oldSchemas.length === 0) {
            return;
        }
        var schema = this._schemaPath.resolve(document);
        if (this.isNullOrUndefined(schema)) {
            return;
        }
        this.copySchemaJsTo(this._oldSchemas, schema, this._childSchemaType);
    };
    return DeleteAllChildSchemasCommand;
}(AbstractSchemaInhCommand));
export { DeleteAllChildSchemasCommand };
DeleteAllChildSchemasCommand["__class"] = "io.apicurio.datamodels.cmd.commands.DeleteAllChildSchemasCommand";
DeleteAllChildSchemasCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=DeleteAllChildSchemasCommand.js.map