"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectNodeContentService = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@loopback/core");
const content_entity_service_1 = require("../content-entity/content-entity.service");
const application_error_1 = require("./../../helper/application-error");
const object_type_service_1 = require("./../object-type.service");
const object_node_service_1 = require("./object-node.service");
let ObjectNodeContentService = class ObjectNodeContentService {
    constructor(objectNodeService, contentEntityService, objectTypeService) {
        this.objectNodeService = objectNodeService;
        this.contentEntityService = contentEntityService;
        this.objectTypeService = objectTypeService;
    }
    async getContent(nodeId, fieldName, contentType, args, ctx) {
        const objectNode = await this.objectNodeService.searchById(nodeId);
        if (!objectNode) {
            return application_error_1.ApplicationError.notFound({ object: nodeId });
        }
        const ObjectType = await this.objectTypeService.searchById(objectNode.objectTypeId);
        if (!ObjectType) {
            return application_error_1.ApplicationError.notFound({
                object: nodeId,
                objectType: objectNode.objectTypeId,
            });
        }
        if (ObjectType.contentType !== contentType) {
            return application_error_1.ApplicationError.wrongValue({
                object: nodeId,
                contentType: contentType,
            });
        }
        return this.contentEntityService.getContent(contentType, objectNode, fieldName, args);
    }
};
ObjectNodeContentService = tslib_1.__decorate([
    core_1.injectable({ scope: core_1.BindingScope.SINGLETON }),
    tslib_1.__param(0, core_1.service(object_node_service_1.ObjectNodeService)),
    tslib_1.__param(1, core_1.service(content_entity_service_1.ContentEntityService)),
    tslib_1.__param(2, core_1.service(object_type_service_1.ObjectTypeService)),
    tslib_1.__metadata("design:paramtypes", [object_node_service_1.ObjectNodeService,
        content_entity_service_1.ContentEntityService,
        object_type_service_1.ObjectTypeService])
], ObjectNodeContentService);
exports.ObjectNodeContentService = ObjectNodeContentService;
//# sourceMappingURL=object-node-content.service.js.map