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 { NodeCompat } from '../../compat/NodeCompat';
import { Constants } from '../../core/Constants';
import { NodePathVisitor } from '../../core/visitors/NodePathVisitor';
/**
 * A node path visitor for AsyncAPI.
 * @author eric.wittmann@gmail.com
 * @author Jakub Senko <jsenko@redhat.com>
 * @class
 * @extends NodePathVisitor
 */
var AaiNodePathVisitor = /** @class */ (function (_super) {
    __extends(AaiNodePathVisitor, _super);
    function AaiNodePathVisitor() {
        return _super.call(this) || this;
    }
    /**
     *
     * @param {AuthorizationCodeOAuthFlow} node
     */
    AaiNodePathVisitor.prototype.visitAuthorizationCodeOAuthFlow = function (node) {
        this.path.prependSegment(Constants.PROP_AUTHORIZATION_CODE, false);
    };
    /**
     *
     * @param {AaiChannelItem} node
     */
    AaiNodePathVisitor.prototype.visitChannelItem = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_CHANNELS, false);
    };
    /**
     *
     * @param {ClientCredentialsOAuthFlow} node
     */
    AaiNodePathVisitor.prototype.visitClientCredentialsOAuthFlow = function (node) {
        this.path.prependSegment(Constants.PROP_CLIENT_CREDENTIALS, false);
    };
    /**
     *
     * @param {Components} node
     */
    AaiNodePathVisitor.prototype.visitComponents = function (node) {
        this.path.prependSegment(Constants.PROP_COMPONENTS, false);
    };
    /**
     *
     * @param {AaiCorrelationId} node
     */
    AaiNodePathVisitor.prototype.visitCorrelationId = function (node) {
        if (node.getName() != null) {
            this.path.prependSegment(node.getName(), true);
            this.path.prependSegment(Constants.PROP_CORRELATION_IDS, false);
        }
        else {
            this.path.prependSegment(Constants.PROP_CORRELATION_ID, false);
        }
    };
    /**
     *
     * @param {AaiHeaderItem} node
     */
    AaiNodePathVisitor.prototype.visitHeaderItem = function (node) {
        this.path.prependSegment(Constants.PROP_HEADERS, false);
    };
    /**
     *
     * @param {ImplicitOAuthFlow} node
     */
    AaiNodePathVisitor.prototype.visitImplicitOAuthFlow = function (node) {
        this.path.prependSegment(Constants.PROP_IMPLICIT, false);
    };
    /**
     *
     * @param {AaiMessage} node
     */
    AaiNodePathVisitor.prototype.visitMessage = function (node) {
        if (node.getName() != null) {
            this.path.prependSegment(node.getName(), true);
            this.path.prependSegment(Constants.PROP_MESSAGES, false);
        }
        else {
            if (!node._isOneOfMessage) {
                this.path.prependSegment(Constants.PROP_MESSAGE, false);
            }
            else {
                var idx = NodeCompat.indexOf(node, node.parent(), Constants.PROP_ONE_OF);
                if (idx !== -1) {
                    this.path.prependSegment(/* valueOf */ new String(idx).toString(), true);
                    this.path.prependSegment(Constants.PROP_ONE_OF, false);
                }
                else {
                    throw Object.defineProperty(new Error("oneOf message without an index"), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.IllegalStateException', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.Exception'] });
                }
            }
        }
    };
    /**
     *
     * @param {AaiMessageTrait} node
     */
    AaiNodePathVisitor.prototype.visitMessageTrait = function (node) {
        var idx = NodeCompat.indexOf(node, node.parent(), Constants.PROP_TRAITS);
        if (idx !== -1) {
            this.path.prependSegment(/* valueOf */ new String(idx).toString(), true);
            this.path.prependSegment(Constants.PROP_TRAITS, false);
        }
        else {
            throw Object.defineProperty(new Error("message trait without an index"), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.IllegalStateException', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.Exception'] });
        }
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitMessageTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition)
     * @param {AaiMessageTraitDefinition} node
     */
    AaiNodePathVisitor.prototype.visitMessageTraitDefinition = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_MESSAGE_TRAITS, false);
    };
    /**
     *
     * @param {OAuthFlows} node
     */
    AaiNodePathVisitor.prototype.visitOAuthFlows = function (node) {
        this.path.prependSegment(Constants.PROP_FLOWS, false);
    };
    /**
     *
     * @param {AaiOperationTrait} node
     */
    AaiNodePathVisitor.prototype.visitOperationTrait = function (node) {
        var idx = NodeCompat.indexOf(node, node.parent(), Constants.PROP_TRAITS);
        if (idx !== -1) {
            this.path.prependSegment(/* valueOf */ new String(idx).toString(), true);
            this.path.prependSegment(Constants.PROP_TRAITS, false);
        }
        else {
            throw Object.defineProperty(new Error("operation trait without an index"), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.IllegalStateException', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.Exception'] });
        }
    };
    /**
     *
     * @param {AaiOperationTraitDefinition} node
     */
    AaiNodePathVisitor.prototype.visitOperationTraitDefinition = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_OPERATION_TRAITS, false);
    };
    /**
     *
     * @param {PasswordOAuthFlow} node
     */
    AaiNodePathVisitor.prototype.visitPasswordOAuthFlow = function (node) {
        this.path.prependSegment(Constants.PROP_PASSWORD, false);
    };
    /**
     *
     * @param {SecurityScheme} node
     */
    AaiNodePathVisitor.prototype.visitSecurityScheme = function (node) {
        this.path.prependSegment(node.getSchemeName(), true);
        this.path.prependSegment(Constants.PROP_SECURITY_SCHEMES, false);
    };
    /**
     *
     * @param {Server} node
     */
    AaiNodePathVisitor.prototype.visitServer = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_SERVERS, false);
    };
    /**
     *
     * @param {ServerVariable} node
     */
    AaiNodePathVisitor.prototype.visitServerVariable = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_VARIABLES, false);
    };
    /**
     *
     * @param {AaiParameter} node
     */
    AaiNodePathVisitor.prototype.visitAaiParameter = function (node) {
        if (node.getName() != null) {
            this.path.prependSegment(node.getName(), true);
            this.path.prependSegment(Constants.PROP_PARAMETERS, false);
        }
        else {
            var idx = NodeCompat.indexOf(node, node.parent(), Constants.PROP_PARAMETERS);
            if (idx !== -1) {
                this.path.prependSegment(/* valueOf */ new String(idx).toString(), true);
                this.path.prependSegment(Constants.PROP_PARAMETERS, false);
            }
        }
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitServerBindings(io.apicurio.datamodels.asyncapi.models.AaiServerBindings)
     * @param {AaiServerBindings} node
     */
    AaiNodePathVisitor.prototype.visitServerBindings = function (node) {
        this.path.prependSegment(Constants.PROP_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitServerBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiServerBindingsDefinition)
     * @param {AaiServerBindingsDefinition} node
     */
    AaiNodePathVisitor.prototype.visitServerBindingsDefinition = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_SERVER_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitOperationBindings(io.apicurio.datamodels.asyncapi.models.AaiOperationBindings)
     * @param {AaiOperationBindings} node
     */
    AaiNodePathVisitor.prototype.visitOperationBindings = function (node) {
        this.path.prependSegment(Constants.PROP_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitOperationBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition)
     * @param {AaiOperationBindingsDefinition} node
     */
    AaiNodePathVisitor.prototype.visitOperationBindingsDefinition = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_OPERATION_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitMessageBindings(io.apicurio.datamodels.asyncapi.models.AaiMessageBindings)
     * @param {AaiMessageBindings} node
     */
    AaiNodePathVisitor.prototype.visitMessageBindings = function (node) {
        this.path.prependSegment(Constants.PROP_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitMessageBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition)
     * @param {AaiMessageBindingsDefinition} node
     */
    AaiNodePathVisitor.prototype.visitMessageBindingsDefinition = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_MESSAGE_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitChannelBindings(io.apicurio.datamodels.asyncapi.models.AaiChannelBindings)
     * @param {AaiChannelBindings} node
     */
    AaiNodePathVisitor.prototype.visitChannelBindings = function (node) {
        this.path.prependSegment(Constants.PROP_BINDINGS, false);
    };
    /**
     * @see io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor#visitChannelBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition)
     * @param {AaiChannelBindingsDefinition} node
     */
    AaiNodePathVisitor.prototype.visitChannelBindingsDefinition = function (node) {
        this.path.prependSegment(node.getName(), true);
        this.path.prependSegment(Constants.PROP_CHANNEL_BINDINGS, false);
    };
    return AaiNodePathVisitor;
}(NodePathVisitor));
export { AaiNodePathVisitor };
AaiNodePathVisitor["__class"] = "io.apicurio.datamodels.asyncapi.visitors.AaiNodePathVisitor";
AaiNodePathVisitor["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor"];
//# sourceMappingURL=AaiNodePathVisitor.js.map