"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectTypeController = void 0;
const tslib_1 = require("tslib");
const authentication_1 = require("@loopback/authentication");
const authorization_1 = require("@loopback/authorization");
const core_1 = require("@loopback/core");
const rest_1 = require("@loopback/rest");
const models_1 = require("../models");
const application_service_1 = require("../services/application.service");
const object_sub_type_model_1 = require("./../models/object-sub-type.model");
const access_rights_const_1 = require("./../services/access-rights/access-rights.const");
const object_type_service_1 = require("./../services/object-type.service");
let ObjectTypeController = class ObjectTypeController {
    constructor(objectTypeService) {
        this.objectTypeService = objectTypeService;
    }
    async create(objectType, ctx) {
        return this.objectTypeService.add(objectType, ctx);
    }
    async find(ctx) {
        return this.objectTypeService.search(ctx);
    }
    updateById(id, objectType, ctx) {
        return this.objectTypeService.modifyById(id, objectType, ctx);
    }
    deleteById(id, ctx) {
        return this.objectTypeService.removeById(id, ctx);
    }
    async createSubType(id, objectSubType, ctx) {
        return this.objectTypeService.createSubType(id, objectSubType);
    }
    async updateSubTypeById(objectTypeId, id, objectSubType, ctx) {
        return this.objectTypeService.modifySubTypeById(objectTypeId, id, objectSubType);
    }
    async deleteSubTypeById(objectTypeId, id, ctx) {
        await this.objectTypeService.removeSubTypeById(objectTypeId, id);
    }
};
tslib_1.__decorate([
    authentication_1.authenticate('jwt'),
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectType,
        scopes: [access_rights_const_1.AccessRightsScope.create],
    }),
    rest_1.post('/object-types', {
        responses: {
            '200': {
                description: 'ObjectType model instance',
                content: { 'application/json': { schema: rest_1.getModelSchemaRef(models_1.ObjectType) } },
            },
        },
    }),
    tslib_1.__param(0, rest_1.requestBody({
        content: {
            'application/json': {
                schema: rest_1.getModelSchemaRef(models_1.ObjectType, {
                    title: 'NewObjectType',
                    exclude: ['id', 'uri'],
                }),
            },
        },
    })),
    tslib_1.__param(1, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [Object, application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "create", null);
tslib_1.__decorate([
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectType,
        scopes: [access_rights_const_1.AccessRightsScope.read],
    }),
    rest_1.get('/object-types', {
        responses: {
            '200': {
                description: 'Array of ObjectType model instances',
                content: {
                    'application/json': {
                        schema: {
                            type: 'array',
                            items: rest_1.getModelSchemaRef(models_1.ObjectType, { includeRelations: true }),
                        },
                    },
                },
            },
        },
    }),
    tslib_1.__param(0, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "find", null);
tslib_1.__decorate([
    authentication_1.authenticate('jwt'),
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectType,
        scopes: [access_rights_const_1.AccessRightsScope.update],
    }),
    rest_1.patch('/object-types/{id}', {
        responses: {
            '204': {
                description: 'ObjectType PATCH success',
                content: { 'application/json': { schema: rest_1.getModelSchemaRef(models_1.ObjectType) } },
            },
        },
    }),
    tslib_1.__param(0, rest_1.param.path.string('id')),
    tslib_1.__param(1, rest_1.requestBody({
        content: {
            'application/json': {
                schema: rest_1.getModelSchemaRef(models_1.ObjectType, { partial: true }),
            },
        },
    })),
    tslib_1.__param(2, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, models_1.ObjectType,
        application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "updateById", null);
tslib_1.__decorate([
    authentication_1.authenticate('jwt'),
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectType,
        scopes: [access_rights_const_1.AccessRightsScope.delete],
    }),
    rest_1.del('/object-types/{id}', {
        responses: {
            '204': {
                description: 'ObjectType DELETE success',
            },
        },
    }),
    tslib_1.__param(0, rest_1.param.path.string('id')),
    tslib_1.__param(1, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "deleteById", null);
tslib_1.__decorate([
    authentication_1.authenticate('jwt'),
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectSubType,
        scopes: [access_rights_const_1.AccessRightsScope.create],
    }),
    rest_1.post('/object-types/{id}/object-sub-types', {
        responses: {
            '200': {
                description: 'ObjectType model instance',
                content: {
                    'application/json': { schema: rest_1.getModelSchemaRef(object_sub_type_model_1.ObjectSubType) },
                },
            },
        },
    }),
    tslib_1.__param(0, rest_1.param.path.string('id')),
    tslib_1.__param(1, rest_1.requestBody({
        content: {
            'application/json': {
                schema: rest_1.getModelSchemaRef(object_sub_type_model_1.ObjectSubType, {
                    title: 'NewObjectSubTypeInObjectType',
                    exclude: ['id', 'uri', 'objectTypeId'],
                    optional: ['objectTypeId'],
                }),
            },
        },
    })),
    tslib_1.__param(2, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [Object, Object, application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "createSubType", null);
tslib_1.__decorate([
    authentication_1.authenticate('jwt'),
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectSubType,
        scopes: [access_rights_const_1.AccessRightsScope.update],
    }),
    rest_1.patch('/object-types/{objectTypeId}/object-sub-types/{id}', {
        responses: {
            '204': {
                description: 'ObjectSubType PATCH success',
                content: {
                    'application/json': { schema: rest_1.getModelSchemaRef(object_sub_type_model_1.ObjectSubType) },
                },
            },
        },
    }),
    tslib_1.__param(0, rest_1.param.path.string('objectTypeId')),
    tslib_1.__param(1, rest_1.param.path.string('id')),
    tslib_1.__param(2, rest_1.requestBody({
        content: {
            'application/json': {
                schema: rest_1.getModelSchemaRef(object_sub_type_model_1.ObjectSubType, { partial: true }),
            },
        },
    })),
    tslib_1.__param(3, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, String, object_sub_type_model_1.ObjectSubType,
        application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "updateSubTypeById", null);
tslib_1.__decorate([
    authentication_1.authenticate('jwt'),
    authorization_1.authorize({
        resource: access_rights_const_1.AccessRightsEntity.objectSubType,
        scopes: [access_rights_const_1.AccessRightsScope.delete],
    }),
    rest_1.del('/object-types/{objectTypeId}/object-sub-types/{id}', {
        responses: {
            '204': {
                description: 'ObjectSubType DELETE success',
            },
        },
    }),
    tslib_1.__param(0, rest_1.param.path.string('objectTypeId')),
    tslib_1.__param(1, rest_1.param.path.string('id')),
    tslib_1.__param(2, core_1.inject(application_service_1.CURRENT_CONTEXT)),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [String, String, application_service_1.CurrentContext]),
    tslib_1.__metadata("design:returntype", Promise)
], ObjectTypeController.prototype, "deleteSubTypeById", null);
ObjectTypeController = tslib_1.__decorate([
    tslib_1.__param(0, core_1.service(object_type_service_1.ObjectTypeService)),
    tslib_1.__metadata("design:paramtypes", [object_type_service_1.ObjectTypeService])
], ObjectTypeController);
exports.ObjectTypeController = ObjectTypeController;
//# sourceMappingURL=object-type.controller.js.map