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 __());
    };
})();
import { JsonCompat } from '../../compat/JsonCompat';
import { Constants } from '../../core/Constants';
import { DataModelWriter } from '../../core/io/DataModelWriter';
/**
 * @author eric.wittmann@gmail.com
 * @author Jakub Senko <jsenko@redhat.com>
 * @class
 * @extends DataModelWriter
 */
var AaiDataModelWriter = /** @class */ (function (_super) {
    __extends(AaiDataModelWriter, _super);
    function AaiDataModelWriter() {
        return _super.call(this) || this;
    }
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeDocument(io.apicurio.datamodels.core.models.Document, java.lang.Object)
     * @param {Document} node
     * @param {*} json
     */
    AaiDataModelWriter.prototype.writeDocument = function (node, json) {
        var aaiNode = node;
        JsonCompat.setPropertyString(json, Constants.PROP_ASYNCAPI, aaiNode.asyncapi);
        JsonCompat.setPropertyString(json, Constants.PROP_ID, aaiNode.id);
        JsonCompat.setPropertyString(json, Constants.PROP_DEFAULT_CONTENT_TYPE, aaiNode.defaultContentType);
        JsonCompat.setPropertyNull(json, Constants.PROP_INFO);
        JsonCompat.setPropertyNull(json, Constants.PROP_SERVERS);
        JsonCompat.setPropertyNull(json, Constants.PROP_CHANNELS);
        JsonCompat.setPropertyNull(json, Constants.PROP_COMPONENTS);
        JsonCompat.setPropertyNull(json, Constants.PROP_TAGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_EXTERNAL_DOCS);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {Server} node
     */
    AaiDataModelWriter.prototype.visitServer = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        this.writeServer(json, node);
        var servers = JsonCompat.getProperty(parent, Constants.PROP_SERVERS);
        if (servers == null) {
            servers = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_SERVERS, servers);
        }
        JsonCompat.setProperty(servers, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    AaiDataModelWriter.prototype.writeServer = function (json, node) {
        JsonCompat.setPropertyString(json, Constants.PROP_URL, node.url);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setPropertyNull(json, Constants.PROP_VARIABLES);
        var server = node;
        JsonCompat.setPropertyString(json, Constants.PROP_PROTOCOL, server.protocol);
        JsonCompat.setPropertyString(json, Constants.PROP_PROTOCOL_VERSION, server.protocolVersion);
        JsonCompat.setPropertyNull(json, Constants.PROP_SECURITY);
        JsonCompat.setPropertyNull(json, Constants.PROP_BINDINGS);
    };
    /**
     *
     * @param {ServerVariable} node
     */
    AaiDataModelWriter.prototype.visitServerVariable = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        this.writeServerVariable(json, node);
        this.writeExtraProperties(json, node);
        var variables = JsonCompat.getProperty(parent, Constants.PROP_VARIABLES);
        if (variables == null) {
            variables = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_VARIABLES, variables);
        }
        JsonCompat.setProperty(variables, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    AaiDataModelWriter.prototype.writeServerVariable = function (json, node) {
        JsonCompat.setPropertyStringArray(json, Constants.PROP_ENUM, node.enum_);
        JsonCompat.setPropertyString(json, Constants.PROP_DEFAULT, node.default_);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setPropertyNull(json, Constants.PROP_VARIABLES);
        var serverVar = node;
        JsonCompat.setPropertyStringArray(json, Constants.PROP_EXAMPLES, serverVar.examples);
    };
    /**
     *
     * @param {AuthorizationCodeOAuthFlow} node
     */
    AaiDataModelWriter.prototype.visitAuthorizationCodeOAuthFlow = function (node) {
        this.doVisitOAuthFlow(node, Constants.PROP_AUTHORIZATION_CODE);
    };
    /**
     *
     * @param {AaiChannelItem} node
     */
    AaiDataModelWriter.prototype.visitChannelItem = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setPropertyNull(json, Constants.PROP_PUBLISH);
        JsonCompat.setPropertyNull(json, Constants.PROP_SUBSCRIBE);
        JsonCompat.setPropertyNull(json, Constants.PROP_PARAMETERS);
        JsonCompat.setPropertyNull(json, Constants.PROP_BINDINGS);
        var map = JsonCompat.getProperty(parent, Constants.PROP_CHANNELS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_CHANNELS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {ClientCredentialsOAuthFlow} node
     */
    AaiDataModelWriter.prototype.visitClientCredentialsOAuthFlow = function (node) {
        this.doVisitOAuthFlow(node, Constants.PROP_CLIENT_CREDENTIALS);
    };
    /**
     *
     * @param {Components} node
     */
    AaiDataModelWriter.prototype.visitComponents = function (node) {
        var components = node;
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        var schemas = JsonCompat.objectNode();
        if (components.schemas != null) {
            {
                var array162 = /* entrySet */ (function (o) { var s = []; for (var e in o)
                    s.push({ k: e, v: o[e], getKey: function () { return this.k; }, getValue: function () { return this.v; } }); return s; })(components.schemas);
                for (var index161 = 0; index161 < array162.length; index161++) {
                    var e = array162[index161];
                    {
                        JsonCompat.setProperty(schemas, e.getKey(), e.getValue());
                    }
                }
            }
            JsonCompat.setProperty(json, Constants.PROP_SCHEMAS, schemas);
        }
        JsonCompat.setPropertyNull(json, Constants.PROP_MESSAGES);
        JsonCompat.setPropertyNull(json, Constants.PROP_SECURITY_SCHEMES);
        JsonCompat.setPropertyNull(json, Constants.PROP_PARAMETERS);
        JsonCompat.setPropertyNull(json, Constants.PROP_CORRELATION_IDS);
        JsonCompat.setPropertyNull(json, Constants.PROP_OPERATION_TRAITS);
        JsonCompat.setPropertyNull(json, Constants.PROP_MESSAGE_TRAITS);
        JsonCompat.setPropertyNull(json, Constants.PROP_SERVER_BINDINGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_CHANNEL_BINDINGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_OPERATION_BINDINGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_MESSAGE_BINDINGS);
        JsonCompat.setProperty(parent, Constants.PROP_COMPONENTS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {AaiCorrelationId} node
     */
    AaiDataModelWriter.prototype.visitCorrelationId = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_LOCATION, node.location);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        if (node.getName() != null) {
            var map = JsonCompat.getProperty(parent, Constants.PROP_CORRELATION_IDS);
            if (map == null) {
                map = JsonCompat.objectNode();
                JsonCompat.setProperty(parent, Constants.PROP_CORRELATION_IDS, map);
            }
            JsonCompat.setProperty(map, node.getName(), json);
        }
        else {
            JsonCompat.setProperty(parent, Constants.PROP_CORRELATION_ID, json);
        }
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {AaiHeaderItem} node
     */
    AaiDataModelWriter.prototype.visitHeaderItem = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        if (node.$ref != null) {
            JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        }
        else {
            json = node._schemaRaw;
        }
        JsonCompat.setProperty(parent, Constants.PROP_HEADERS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    AaiDataModelWriter.prototype.doVisitOAuthFlow = function (node, flowName) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_AUTHORIZATION_URL, node.authorizationUrl);
        JsonCompat.setPropertyString(json, Constants.PROP_TOKEN_URL, node.tokenUrl);
        JsonCompat.setPropertyString(json, Constants.PROP_REFRESH_URL, node.refreshUrl);
        JsonCompat.setProperty(json, Constants.PROP_SCOPES, node.scopes);
        JsonCompat.setProperty(parent, flowName, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {ImplicitOAuthFlow} node
     */
    AaiDataModelWriter.prototype.visitImplicitOAuthFlow = function (node) {
        this.doVisitOAuthFlow(node, Constants.PROP_IMPLICIT);
    };
    /*private*/ AaiDataModelWriter.prototype.writeMessageBase = function (node) {
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyNull(json, Constants.PROP_HEADERS);
        JsonCompat.setPropertyNull(json, Constants.PROP_CORRELATION_ID);
        JsonCompat.setPropertyString(json, Constants.PROP_SCHEMA_FORMAT, node.schemaFormat);
        JsonCompat.setPropertyString(json, Constants.PROP_CONTENT_TYPE, node.contentType);
        JsonCompat.setPropertyString(json, Constants.PROP_NAME, node.name);
        JsonCompat.setPropertyString(json, Constants.PROP_TITLE, node.title);
        JsonCompat.setPropertyString(json, Constants.PROP_SUMMARY, node.summary);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        JsonCompat.setPropertyNull(json, Constants.PROP_TAGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_EXTERNAL_DOCS);
        JsonCompat.setPropertyNull(json, Constants.PROP_BINDINGS);
        return json;
    };
    /**
     *
     * @param {AaiMessage} node
     */
    AaiDataModelWriter.prototype.visitMessage = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = this.writeMessageBase(node);
        JsonCompat.setProperty(json, Constants.PROP_PAYLOAD, node.payload);
        JsonCompat.setPropertyNull(json, Constants.PROP_TRAITS);
        if (node.getName() != null) {
            var map = JsonCompat.getProperty(parent, Constants.PROP_MESSAGES);
            if (map == null) {
                map = JsonCompat.objectNode();
                JsonCompat.setProperty(parent, Constants.PROP_MESSAGES, map);
            }
            JsonCompat.setProperty(map, node.getName(), json);
        }
        else {
            if (node._isOneOfMessage) {
                var list = JsonCompat.getProperty(parent, Constants.PROP_ONE_OF);
                if (list == null) {
                    list = JsonCompat.arrayNode();
                    JsonCompat.setProperty(parent, Constants.PROP_ONE_OF, list);
                }
                JsonCompat.appendToArray(list, json);
            }
            else {
                JsonCompat.setProperty(parent, Constants.PROP_MESSAGE, json);
            }
        }
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {AaiMessageTrait} node
     */
    AaiDataModelWriter.prototype.visitMessageTrait = function (node) {
        var json = this.writeMessageBase(node);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        JsonCompat.appendToArrayProperty(parent, Constants.PROP_TRAITS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {OAuthFlows} node
     */
    AaiDataModelWriter.prototype.visitOAuthFlows = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyNull(json, Constants.PROP_IMPLICIT);
        JsonCompat.setPropertyNull(json, Constants.PROP_PASSWORD);
        JsonCompat.setPropertyNull(json, Constants.PROP_CLIENT_CREDENTIALS);
        JsonCompat.setPropertyNull(json, Constants.PROP_AUTHORIZATION_CODE);
        JsonCompat.setProperty(parent, Constants.PROP_FLOWS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {*} json
     * @param {Operation} node
     */
    AaiDataModelWriter.prototype.writeOperation = function (json, node) {
        var aaiNode = node;
        _super.prototype.writeOperation.call(this, json, aaiNode);
    };
    AaiDataModelWriter.prototype.writeOperationBase = function (node) {
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        JsonCompat.setPropertyString(json, Constants.PROP_OPERATION_ID, node.operationId);
        JsonCompat.setPropertyString(json, Constants.PROP_SUMMARY, node.summary);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setPropertyNull(json, Constants.PROP_EXTERNAL_DOCS);
        JsonCompat.setPropertyNull(json, Constants.PROP_TAGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_BINDINGS);
        return json;
    };
    /**
     *
     * @param {Operation} node
     */
    AaiDataModelWriter.prototype.visitOperation = function (node) {
        var aaiNode = node;
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = this.writeOperationBase(aaiNode);
        JsonCompat.setPropertyNull(json, Constants.PROP_TRAITS);
        JsonCompat.setPropertyNull(json, Constants.PROP_MESSAGE);
        JsonCompat.setProperty(parent, node.getType(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {AaiOperationTrait} node
     */
    AaiDataModelWriter.prototype.visitOperationTrait = function (node) {
        var json = this.writeOperationBase(node);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        JsonCompat.appendToArrayProperty(parent, Constants.PROP_TRAITS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {PasswordOAuthFlow} node
     */
    AaiDataModelWriter.prototype.visitPasswordOAuthFlow = function (node) {
        this.doVisitOAuthFlow(node, Constants.PROP_PASSWORD);
    };
    /**
     *
     * @param {AaiParameter} node
     */
    AaiDataModelWriter.prototype.visitAaiParameter = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
        JsonCompat.setProperty(json, Constants.PROP_SCHEMA, node.schema);
        JsonCompat.setPropertyString(json, Constants.PROP_LOCATION, node.location);
        if (node.getName() != null) {
            var map = JsonCompat.getProperty(parent, Constants.PROP_PARAMETERS);
            if (map == null) {
                map = JsonCompat.objectNode();
                JsonCompat.setProperty(parent, Constants.PROP_PARAMETERS, map);
            }
            JsonCompat.setProperty(map, node.getName(), json);
        }
        else {
            var list = JsonCompat.getProperty(parent, Constants.PROP_PARAMETERS);
            if (list == null) {
                list = JsonCompat.arrayNode();
                JsonCompat.setProperty(parent, Constants.PROP_PARAMETERS, list);
            }
            JsonCompat.appendToArray(list, json);
        }
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     *
     * @param {*} parent
     * @param {*} json
     * @param {SecurityScheme} node
     */
    AaiDataModelWriter.prototype.addSecuritySchemeToParent = function (parent, json, node) {
        if (node.getName() != null) {
            var map = JsonCompat.getProperty(parent, Constants.PROP_SECURITY_SCHEMES);
            if (map == null) {
                map = JsonCompat.objectNode();
                JsonCompat.setProperty(parent, Constants.PROP_SECURITY_SCHEMES, map);
            }
            JsonCompat.setProperty(map, node.getName(), json);
        }
        else {
            throw Object.defineProperty(new Error("error in writing a security scheme"), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.IllegalStateException', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.Exception'] });
        }
    };
    /**
     *
     * @param {*} json
     * @param {SecurityScheme} node
     */
    AaiDataModelWriter.prototype.writeSecurityScheme = function (json, node) {
        var aaiNode = node;
        _super.prototype.writeSecurityScheme.call(this, json, node);
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, aaiNode.$ref);
        JsonCompat.setPropertyString(json, Constants.PROP_SCHEME, aaiNode.scheme);
        JsonCompat.setPropertyString(json, Constants.PROP_OPEN_ID_CONNECT_URL, aaiNode.openIdConnectUrl);
        JsonCompat.setPropertyString(json, Constants.PROP_BEARER_FORMAT, aaiNode.bearerFormat);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitMessageTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition)
     * @param {AaiMessageTraitDefinition} node
     */
    AaiDataModelWriter.prototype.visitMessageTraitDefinition = function (node) {
        var json = this.writeMessageBase(node);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var map = JsonCompat.getProperty(parent, Constants.PROP_MESSAGE_TRAITS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_MESSAGE_TRAITS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitOperationTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationTraitDefinition)
     * @param {AaiOperationTraitDefinition} node
     */
    AaiDataModelWriter.prototype.visitOperationTraitDefinition = function (node) {
        var json = this.writeOperationBase(node);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var map = JsonCompat.getProperty(parent, Constants.PROP_OPERATION_TRAITS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_OPERATION_TRAITS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitServerBindings(io.apicurio.datamodels.asyncapi.models.AaiServerBindings)
     * @param {AaiServerBindings} node
     */
    AaiDataModelWriter.prototype.visitServerBindings = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        JsonCompat.setProperty(parent, Constants.PROP_BINDINGS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitServerBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiServerBindingsDefinition)
     * @param {AaiServerBindingsDefinition} node
     */
    AaiDataModelWriter.prototype.visitServerBindingsDefinition = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var map = JsonCompat.getProperty(parent, Constants.PROP_SERVER_BINDINGS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_SERVER_BINDINGS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitOperationBindings(io.apicurio.datamodels.asyncapi.models.AaiOperationBindings)
     * @param {AaiOperationBindings} node
     */
    AaiDataModelWriter.prototype.visitOperationBindings = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        JsonCompat.setProperty(parent, Constants.PROP_BINDINGS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitOperationBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition)
     * @param {AaiOperationBindingsDefinition} node
     */
    AaiDataModelWriter.prototype.visitOperationBindingsDefinition = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var map = JsonCompat.getProperty(parent, Constants.PROP_OPERATION_BINDINGS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_OPERATION_BINDINGS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitMessageBindings(io.apicurio.datamodels.asyncapi.models.AaiMessageBindings)
     * @param {AaiMessageBindings} node
     */
    AaiDataModelWriter.prototype.visitMessageBindings = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        JsonCompat.setProperty(parent, Constants.PROP_BINDINGS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitMessageBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition)
     * @param {AaiMessageBindingsDefinition} node
     */
    AaiDataModelWriter.prototype.visitMessageBindingsDefinition = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var map = JsonCompat.getProperty(parent, Constants.PROP_MESSAGE_BINDINGS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_MESSAGE_BINDINGS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitChannelBindings(io.apicurio.datamodels.asyncapi.models.AaiChannelBindings)
     * @param {AaiChannelBindings} node
     */
    AaiDataModelWriter.prototype.visitChannelBindings = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        JsonCompat.setProperty(parent, Constants.PROP_BINDINGS, json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitChannelBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition)
     * @param {AaiChannelBindingsDefinition} node
     */
    AaiDataModelWriter.prototype.visitChannelBindingsDefinition = function (node) {
        var json = this.writeNullBindings();
        JsonCompat.setProperty(json, Constants.PROP_HTTP, node.http);
        JsonCompat.setProperty(json, Constants.PROP_WS, node.ws);
        JsonCompat.setProperty(json, Constants.PROP_KAFKA, node.kafka);
        JsonCompat.setProperty(json, Constants.PROP_AMQP, node.amqp);
        JsonCompat.setProperty(json, Constants.PROP_AMQP1, node.amqp1);
        JsonCompat.setProperty(json, Constants.PROP_MQTT, node.mqtt);
        JsonCompat.setProperty(json, Constants.PROP_MQTT5, node.mqtt5);
        JsonCompat.setProperty(json, Constants.PROP_NATS, node.nats);
        JsonCompat.setProperty(json, Constants.PROP_JMS, node.jms);
        JsonCompat.setProperty(json, Constants.PROP_SNS, node.sns);
        JsonCompat.setProperty(json, Constants.PROP_SQS, node.sqs);
        JsonCompat.setProperty(json, Constants.PROP_STOMP, node.stomp);
        JsonCompat.setProperty(json, Constants.PROP_REDIS, node.redis);
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var map = JsonCompat.getProperty(parent, Constants.PROP_CHANNEL_BINDINGS);
        if (map == null) {
            map = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_CHANNEL_BINDINGS, map);
        }
        JsonCompat.setProperty(map, node.getName(), json);
        this.writeExtraProperties(json, node);
        this.updateIndex(node, json);
    };
    /**
     * Writes a Server/Channel/Operation/Message Bindings model to JSON.
     * @param node
     * @return {*}
     */
    AaiDataModelWriter.prototype.writeNullBindings = function () {
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyNull(json, Constants.PROP_HTTP);
        JsonCompat.setPropertyNull(json, Constants.PROP_WS);
        JsonCompat.setPropertyNull(json, Constants.PROP_KAFKA);
        JsonCompat.setPropertyNull(json, Constants.PROP_AMQP);
        JsonCompat.setPropertyNull(json, Constants.PROP_AMQP1);
        JsonCompat.setPropertyNull(json, Constants.PROP_MQTT);
        JsonCompat.setPropertyNull(json, Constants.PROP_MQTT5);
        JsonCompat.setPropertyNull(json, Constants.PROP_NATS);
        JsonCompat.setPropertyNull(json, Constants.PROP_JMS);
        JsonCompat.setPropertyNull(json, Constants.PROP_SNS);
        JsonCompat.setPropertyNull(json, Constants.PROP_SQS);
        JsonCompat.setPropertyNull(json, Constants.PROP_STOMP);
        JsonCompat.setPropertyNull(json, Constants.PROP_REDIS);
        return json;
    };
    return AaiDataModelWriter;
}(DataModelWriter));
export { AaiDataModelWriter };
AaiDataModelWriter["__class"] = "io.apicurio.datamodels.asyncapi.io.AaiDataModelWriter";
AaiDataModelWriter["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor"];
//# sourceMappingURL=AaiDataModelWriter.js.map