"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityDefinitionService = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@loopback/core");
const extension_description_1 = require("./../../integration/extension-description");
const application_service_1 = require("./../application.service");
const entity_definition_cont_1 = require("./entity-definition.cont");
let EntityDefinitionService = class EntityDefinitionService {
    constructor(appCtx) {
        this.appCtx = appCtx;
        this.entityDefinitions = {};
    }
    registerEntityDefinitionService(resource, entityDefinition) {
        this.entityDefinitions[resource] = entityDefinition;
    }
    getPostTreatmentDescription() {
        const treatments = [];
        for (const resource in this.entityDefinitions) {
            treatments.push(new extension_description_1.TreatmentDescription(this.entityDefinitions[resource].providerId, this.entityDefinitions[resource].serviceId, resource + ':  Add Json Schema definition'));
        }
        return treatments;
    }
    get ready() {
        return this.appCtx.getExtensionContext(entity_definition_cont_1.ENTITY_DEFINITION_PROVIDER).ready;
    }
    async completeReturnedEntity(entityName, entity, ctx) {
        var _a;
        if (entityName in this.entityDefinitions) {
            await ((_a = this.entityDefinitions[entityName]) === null || _a === void 0 ? void 0 : _a.completeReturnedEntity(entity, ctx));
        }
    }
    async completeReturnedEntities(entityName, entities, ctx) {
        for (let childIndex = entities.length - 1; childIndex >= 0; childIndex--) {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            const entity = entities[childIndex];
            await this.completeReturnedEntity(entityName, entity, ctx);
        }
    }
};
EntityDefinitionService = tslib_1.__decorate([
    core_1.injectable({ scope: core_1.BindingScope.SINGLETON }),
    tslib_1.__param(0, core_1.service(application_service_1.ApplicationService)),
    tslib_1.__metadata("design:paramtypes", [application_service_1.ApplicationService])
], EntityDefinitionService);
exports.EntityDefinitionService = EntityDefinitionService;
//# sourceMappingURL=entity-definition.service.js.map