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 { ModernSecurityScheme } from '../../../core/models/common/ModernSecurityScheme';
import { Oas30Callback } from '../../v3/models/Oas30Callback';
import { Oas30CallbackDefinition } from '../../v3/models/Oas30CallbackDefinition';
import { Oas30Document } from '../../v3/models/Oas30Document';
import { Oas30Example } from '../../v3/models/Oas30Example';
import { Oas30ExampleDefinition } from '../../v3/models/Oas30ExampleDefinition';
import { Oas30Header } from '../../v3/models/Oas30Header';
import { Oas30HeaderDefinition } from '../../v3/models/Oas30HeaderDefinition';
import { Oas30Link } from '../../v3/models/Oas30Link';
import { Oas30LinkDefinition } from '../../v3/models/Oas30LinkDefinition';
import { Oas30Parameter } from '../../v3/models/Oas30Parameter';
import { Oas30ParameterDefinition } from '../../v3/models/Oas30ParameterDefinition';
import { Oas30RequestBody } from '../../v3/models/Oas30RequestBody';
import { Oas30RequestBodyDefinition } from '../../v3/models/Oas30RequestBodyDefinition';
import { Oas30Response } from '../../v3/models/Oas30Response';
import { Oas30ResponseDefinition } from '../../v3/models/Oas30ResponseDefinition';
import { Oas30Schema } from '../../v3/models/Oas30Schema';
import { Oas30SchemaDefinition } from '../../v3/models/Oas30SchemaDefinition';
import { Oas30SecurityScheme } from '../../v3/models/Oas30SecurityScheme';
import { AbstractReferenceLocalizationStrategy } from './AbstractReferenceLocalizationStrategy';
var Oas30IReferenceManipulationStrategy = /** @class */ (function (_super) {
    __extends(Oas30IReferenceManipulationStrategy, _super);
    function Oas30IReferenceManipulationStrategy() {
        return _super.call(this) || this;
    }
    /**
     *
     * @param {Document} document
     * @param {string} name
     * @param {Node} component
     * @return {IReferenceManipulationStrategy.ReferenceAndNode}
     */
    Oas30IReferenceManipulationStrategy.prototype.attachAsDefinition = function (document, name, component) {
        if (!(document != null && document instanceof Oas30Document))
            throw Object.defineProperty(new Error("Oas30Document expected."), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
        var model = document;
        if (component != null && component instanceof Oas30Schema) {
            if (model.components.getSchemaDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30SchemaDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addSchemaDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "schemas/" + name, definition);
        }
        if (component != null && component instanceof Oas30Response) {
            if (model.components.getResponseDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30ResponseDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addResponseDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "responses/" + name, definition);
        }
        if (component != null && component instanceof Oas30Parameter) {
            if (model.components.getParameterDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30ParameterDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addParameterDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "parameters/" + name, definition);
        }
        if (component != null && component instanceof Oas30Example) {
            if (model.components.getExampleDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30ExampleDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addExampleDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "examples/" + name, definition);
        }
        if (component != null && component instanceof Oas30RequestBody) {
            if (model.components.getRequestBodyDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30RequestBodyDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addRequestBodyDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "requestBodies/" + name, definition);
        }
        if (component != null && component instanceof Oas30Header) {
            if (model.components.getHeaderDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30HeaderDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addHeaderDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "headers/" + name, definition);
        }
        if (component != null && component instanceof ModernSecurityScheme) {
            if (model.components.getSecurityScheme(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30SecurityScheme(name), model));
            definition.attachToParent(model.components);
            model.components.addSecurityScheme(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "securitySchemes/" + name, definition);
        }
        if (component != null && component instanceof Oas30Link) {
            if (model.components.getLinkDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30LinkDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addLinkDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "links/" + name, definition);
        }
        if (component != null && component instanceof Oas30Callback) {
            if (model.components.getCallbackDefinition(name) != null)
                throw Object.defineProperty(new Error("Definition with that name already exists: " + name), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
            var definition = (this.wrap(component, new Oas30CallbackDefinition(name), model));
            definition.attachToParent(model.components);
            model.components.addCallbackDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "callbacks/" + name, definition);
        }
        return null;
    };
    /**
     *
     * @param {Document} document
     * @return {*}
     */
    Oas30IReferenceManipulationStrategy.prototype.getExistingLocalComponents = function (document) {
        var _this = this;
        if (!(document != null && document instanceof Oas30Document))
            throw Object.defineProperty(new Error("Oas30Document expected."), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.IllegalArgumentException', 'java.lang.Exception'] });
        var model = document;
        var res = ({});
        if (model.components != null) {
            this.transform(model.components.schemas, function (name) { return _this.PREFIX + "schemas/" + name; }, res);
            this.transform(model.components.responses, function (name) { return _this.PREFIX + "responses/" + name; }, res);
            this.transform(model.components.parameters, function (name) { return _this.PREFIX + "parameters/" + name; }, res);
            this.transform(model.components.examples, function (name) { return _this.PREFIX + "examples/" + name; }, res);
            this.transform(model.components.requestBodies, function (name) { return _this.PREFIX + "requestBodies/" + name; }, res);
            this.transform(model.components.headers, function (name) { return _this.PREFIX + "headers/" + name; }, res);
            this.transform(model.components.securitySchemes, function (name) { return _this.PREFIX + "securitySchemes/" + name; }, res);
            this.transform(model.components.links, function (name) { return _this.PREFIX + "links/" + name; }, res);
            this.transform(model.components.callbacks, function (name) { return _this.PREFIX + "callbacks/" + name; }, res);
        }
        return res;
    };
    return Oas30IReferenceManipulationStrategy;
}(AbstractReferenceLocalizationStrategy));
export { Oas30IReferenceManipulationStrategy };
Oas30IReferenceManipulationStrategy["__class"] = "io.apicurio.datamodels.openapi.visitors.dereference.Oas30IReferenceManipulationStrategy";
Oas30IReferenceManipulationStrategy["__interfaces"] = ["io.apicurio.datamodels.openapi.visitors.dereference.IReferenceManipulationStrategy"];
import { IReferenceManipulationStrategy } from './IReferenceManipulationStrategy';
//# sourceMappingURL=Oas30IReferenceManipulationStrategy.js.map