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 { CombinedVisitorAdapter } from '../../combined/visitors/CombinedVisitorAdapter';
import { DocumentType } from '../../core/models/DocumentType';
/**
 * Constructor.
 * @param {SimplifiedType} type
 * @class
 * @extends CombinedVisitorAdapter
 * @author eric.wittmann@gmail.com
 */
var SetItemsTypeVisitor = /** @class */ (function (_super) {
    __extends(SetItemsTypeVisitor, _super);
    function SetItemsTypeVisitor(type) {
        var _this = _super.call(this) || this;
        if (_this.type === undefined)
            _this.type = null;
        _this.type = type;
        return _this;
    }
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitSchema(io.apicurio.datamodels.core.models.common.Schema)
     * @param {Schema} node
     */
    SetItemsTypeVisitor.prototype.visitSchema = function (node) {
        var schema = node;
        schema.items = schema.createItemsSchema();
        if (ModelUtils.isDefined(this.type.of)) {
            var items = schema.items;
            if (this.type.of.isRef()) {
                items.$ref = this.type.of.type;
            }
            else {
                items.type = this.type.of.type;
                items.format = this.type.of.as;
            }
        }
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitParameter(io.apicurio.datamodels.core.models.common.Parameter)
     * @param {Parameter} node
     */
    SetItemsTypeVisitor.prototype.visitParameter = function (node) {
        if (node.ownerDocument().getDocumentType() === DocumentType.openapi2) {
            var param = node;
            param.items = param.createItems();
            if (ModelUtils.isDefined(this.type.of)) {
                param.items.type = this.type.of.type;
                param.items.format = this.type.of.as;
            }
        }
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitSchemaDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
     * @param {*} node
     */
    SetItemsTypeVisitor.prototype.visitSchemaDefinition = function (node) {
        this.visitSchema(node);
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitPropertySchema(io.apicurio.datamodels.openapi.models.IOasPropertySchema)
     * @param {*} node
     */
    SetItemsTypeVisitor.prototype.visitPropertySchema = function (node) {
        this.visitSchema(node);
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitAdditionalPropertiesSchema(io.apicurio.datamodels.openapi.models.OasSchema)
     * @param {OasSchema} node
     */
    SetItemsTypeVisitor.prototype.visitAdditionalPropertiesSchema = function (node) {
        this.visitSchema(node);
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitAllOfSchema(io.apicurio.datamodels.openapi.models.OasSchema)
     * @param {OasSchema} node
     */
    SetItemsTypeVisitor.prototype.visitAllOfSchema = function (node) {
        this.visitSchema(node);
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitItemsSchema(io.apicurio.datamodels.openapi.models.OasSchema)
     * @param {OasSchema} node
     */
    SetItemsTypeVisitor.prototype.visitItemsSchema = function (node) {
        this.visitSchema(node);
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter#visitParameterDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
     * @param {*} node
     */
    SetItemsTypeVisitor.prototype.visitParameterDefinition = function (node) {
        this.visitParameter(node);
    };
    return SetItemsTypeVisitor;
}(CombinedVisitorAdapter));
export { SetItemsTypeVisitor };
SetItemsTypeVisitor["__class"] = "io.apicurio.datamodels.cmd.util.SetItemsTypeVisitor";
SetItemsTypeVisitor["__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"];
import { ModelUtils } from './ModelUtils';
//# sourceMappingURL=SetItemsTypeVisitor.js.map