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 { ModelUtils } from '../util/ModelUtils';
import { Document } from '../../core/models/Document';
import { ReplaceNodeCommand } from './ReplaceNodeCommand';
import { DocumentType } from '../../core/models/DocumentType';
/**
 * A command used to replace a path item with a newer version.
 * @author eric.wittmann@gmail.com
 * @extends ReplaceNodeCommand
 * @class
 */
var ReplaceDocumentCommand = /** @class */ (function (_super) {
    __extends(ReplaceDocumentCommand, _super);
    function ReplaceDocumentCommand(old, replacement) {
        var _this = this;
        if (((old != null && old instanceof Document) || old === null) && ((replacement != null && replacement instanceof Document) || replacement === null)) {
            var __args = arguments;
            _this = _super.call(this, old, replacement) || this;
        }
        else if (old === undefined && replacement === undefined) {
            var __args = arguments;
            _this = _super.call(this) || this;
        }
        else
            throw new Error('invalid overload');
        return _this;
    }
    ReplaceDocumentCommand.prototype.removeNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_core_models_Document = function (doc, node) {
        switch ((node.getDocumentType())) {
            case DocumentType.asyncapi2:
                this.resetAai2xDocument(node);
                break;
            case DocumentType.openapi2:
                this.resetOas2xDocument(node);
                break;
            case DocumentType.openapi3:
                this.resetOas3xDocument(node);
                break;
            default:
                break;
        }
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#removeNode(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.Node)
     * @param {Document} doc
     * @param {Document} node
     */
    ReplaceDocumentCommand.prototype.removeNode = function (doc, node) {
        if (((doc != null && doc instanceof Document) || doc === null) && ((node != null && node instanceof Document) || node === null)) {
            return this.removeNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_core_models_Document(doc, node);
        }
        else if (((doc != null && doc instanceof Document) || doc === null) && ((node != null) || node === null)) {
            throw new Error('cannot invoke abstract overloaded method... check your argument(s) type(s)');
        }
        else
            throw new Error('invalid overload');
    };
    ReplaceDocumentCommand.prototype.addNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_core_models_Document = function (doc, node) {
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#addNode(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.Node)
     * @param {Document} doc
     * @param {Document} node
     */
    ReplaceDocumentCommand.prototype.addNode = function (doc, node) {
        if (((doc != null && doc instanceof Document) || doc === null) && ((node != null && node instanceof Document) || node === null)) {
            return this.addNode$io_apicurio_datamodels_core_models_Document$io_apicurio_datamodels_core_models_Document(doc, node);
        }
        else if (((doc != null && doc instanceof Document) || doc === null) && ((node != null) || node === null)) {
            throw new Error('cannot invoke abstract overloaded method... check your argument(s) type(s)');
        }
        else
            throw new Error('invalid overload');
    };
    /**
     * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#readNode(io.apicurio.datamodels.core.models.Document, java.lang.Object)
     * @param {Document} doc
     * @param {*} node
     * @return {Document}
     */
    ReplaceDocumentCommand.prototype.readNode = function (doc, node) {
        Library.readNode(node, doc);
        return doc;
    };
    /**
     * Resets a 2.0 OAI document by nulling out all of its properties.
     * @param {Oas20Document} doc
     * @private
     */
    /*private*/ ReplaceDocumentCommand.prototype.resetOas2xDocument = function (doc) {
        doc.host = null;
        doc.basePath = null;
        doc.schemes = null;
        doc.consumes = null;
        doc.produces = null;
        doc.definitions = null;
        doc.parameters = null;
        doc.responses = null;
        doc.securityDefinitions = null;
        this.resetOasDocument(doc);
    };
    /**
     * Resets a 3.x OAI document by nulling out all of its properties.
     * @param {Oas30Document} doc
     * @private
     */
    /*private*/ ReplaceDocumentCommand.prototype.resetOas3xDocument = function (doc) {
        doc.servers = null;
        doc.components = null;
        this.resetOasDocument(doc);
    };
    /**
     * Resets a 2.0 AAI document by nulling out all of its properties.
     * @param {Aai20Document} doc
     * @private
     */
    /*private*/ ReplaceDocumentCommand.prototype.resetAai2xDocument = function (doc) {
        doc.id = null;
        doc.channels = ({});
        doc.servers = null;
        doc.components = null;
        doc.defaultContentType = null;
        this.resetDocument(doc);
    };
    /**
     * Resets the common properties of an OAS doc.
     * @param {OasDocument} doc
     * @private
     */
    /*private*/ ReplaceDocumentCommand.prototype.resetOasDocument = function (doc) {
        doc.paths = null;
        doc.security = null;
        this.resetDocument(doc);
    };
    /**
     * Resets the common properties.
     * @param {Document} doc
     * @private
     */
    /*private*/ ReplaceDocumentCommand.prototype.resetDocument = function (doc) {
        doc.info = null;
        doc.tags = null;
        doc.externalDocs = null;
        var extensions = doc.getExtensions();
        if (ModelUtils.isDefined(extensions)) {
            extensions.forEach(function (ext) {
                doc.removeExtension(ext.name);
            });
        }
        doc.getExtraPropertyNames().forEach(function (pname) {
            doc.removeExtraProperty(pname);
        });
    };
    return ReplaceDocumentCommand;
}(ReplaceNodeCommand));
export { ReplaceDocumentCommand };
ReplaceDocumentCommand["__class"] = "io.apicurio.datamodels.cmd.commands.ReplaceDocumentCommand";
ReplaceDocumentCommand["__interfaces"] = ["io.apicurio.datamodels.cmd.ICommand"];
//# sourceMappingURL=ReplaceDocumentCommand.js.map