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 { Oas20Document } from '../../v2/models/Oas20Document';
import { Oas20Parameter } from '../../v2/models/Oas20Parameter';
import { Oas20ParameterDefinition } from '../../v2/models/Oas20ParameterDefinition';
import { Oas20Response } from '../../v2/models/Oas20Response';
import { Oas20ResponseDefinition } from '../../v2/models/Oas20ResponseDefinition';
import { Oas20Schema } from '../../v2/models/Oas20Schema';
import { Oas20SchemaDefinition } from '../../v2/models/Oas20SchemaDefinition';
import { AbstractReferenceLocalizationStrategy } from './AbstractReferenceLocalizationStrategy';
var Oas20IReferenceManipulationStrategy = /** @class */ (function (_super) {
    __extends(Oas20IReferenceManipulationStrategy, _super);
    function Oas20IReferenceManipulationStrategy() {
        var _this = _super.call(this) || this;
        _this.PREFIX = "#/";
        return _this;
    }
    /**
     *
     * @param {Document} document
     * @param {string} name
     * @param {Node} component
     * @return {IReferenceManipulationStrategy.ReferenceAndNode}
     */
    Oas20IReferenceManipulationStrategy.prototype.attachAsDefinition = function (document, name, component) {
        if (!(document != null && document instanceof Oas20Document))
            throw Object.defineProperty(new Error("Oas20Document 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 Oas20Schema) {
            if (model.definitions == null)
                model.definitions = model.createDefinitions();
            if (model.definitions.getDefinition(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 Oas20SchemaDefinition(name), model));
            definition.attachToParent(model.definitions);
            model.definitions.addDefinition(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "definitions/" + name, definition);
        }
        if (component != null && component instanceof Oas20Parameter) {
            if (model.parameters == null)
                model.parameters = model.createParameterDefinitions();
            if (model.parameters.getParameter(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 Oas20ParameterDefinition(name), model));
            definition.attachToParent(model.parameters);
            model.parameters.addParameter(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "parameters/" + name, definition);
        }
        if (component != null && component instanceof Oas20Response) {
            if (model.responses == null)
                model.responses = model.createResponseDefinitions();
            if (model.responses.getResponse(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 Oas20ResponseDefinition(name), model));
            definition.attachToParent(model.responses);
            model.responses.addResponse(definition.getName(), definition);
            return new IReferenceManipulationStrategy.ReferenceAndNode(this.PREFIX + "responses/" + name, definition);
        }
        return null;
    };
    /**
     *
     * @param {Document} document
     * @return {*}
     */
    Oas20IReferenceManipulationStrategy.prototype.getExistingLocalComponents = function (document) {
        var _this = this;
        if (!(document != null && document instanceof Oas20Document))
            throw Object.defineProperty(new Error("Oas20Document 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.definitions != null)
            this.transform(model.definitions.items, function (name) { return _this.PREFIX + "definitions/" + name; }, res);
        if (model.parameters != null)
            this.transform(model.parameters.items, function (name) { return _this.PREFIX + "parameters/" + name; }, res);
        if (model.responses != null)
            this.transform(model.responses.items, function (name) { return _this.PREFIX + "responses/" + name; }, res);
        return res;
    };
    return Oas20IReferenceManipulationStrategy;
}(AbstractReferenceLocalizationStrategy));
export { Oas20IReferenceManipulationStrategy };
Oas20IReferenceManipulationStrategy["__class"] = "io.apicurio.datamodels.openapi.visitors.dereference.Oas20IReferenceManipulationStrategy";
Oas20IReferenceManipulationStrategy["__interfaces"] = ["io.apicurio.datamodels.openapi.visitors.dereference.IReferenceManipulationStrategy"];
import { IReferenceManipulationStrategy } from './IReferenceManipulationStrategy';
//# sourceMappingURL=Oas20IReferenceManipulationStrategy.js.map