"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var ServiceController_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceController = void 0;
const openapi = require("@nestjs/swagger");
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const public_decorator_1 = require("../decorators/public.decorator");
const error_mapper_service_1 = require("../helpers/error-mapper.service");
const ai_interaction_service_1 = require("../services/ai-interaction.service");
const ingest_metadata_service_1 = require("../services/genai/ingest-metadata.service");
const mq_message_service_1 = require("../services/mq-message.service");
const solid_registry_1 = require("../helpers/solid-registry");
let ServiceController = ServiceController_1 = class ServiceController {
    constructor(solidRegistry, aiInteractionService, mqMessageService, errorMapper, ingestMetadataService) {
        this.solidRegistry = solidRegistry;
        this.aiInteractionService = aiInteractionService;
        this.mqMessageService = mqMessageService;
        this.errorMapper = errorMapper;
        this.ingestMetadataService = ingestMetadataService;
        this.logger = new common_1.Logger(ServiceController_1.name);
    }
    pingPong() {
        return { pong: 'v1.0.2' };
    }
    async seedData(seedData) {
        const seeder = this.solidRegistry
            .getSeeders()
            .filter((seeder) => seeder.name === seedData.seeder)
            .map((seeder) => seeder.instance)
            .pop();
        if (!seeder) {
            this.logger.error(`Seeder service ${seedData.seeder} not found. Does your service have a seed() method?`);
            return;
        }
        this.logger.log(`Running the seed() method for seeder :${seeder.constructor.name}`);
        await seeder.seed();
        return { message: `seed data for ${seedData.seeder}` };
    }
    async postProcessCodeGeneration(config) {
        config.runModuleMetadataSeeder = config.runModuleMetadataSeeder ?? true;
        config.runSolidIngestion = config.runSolidIngestion ?? true;
        if (config.runModuleMetadataSeeder) {
            this.logger.debug(`Running the Module Metadata Seeder Service as part of post-process code generation`);
            const seeder = this.solidRegistry
                .getSeeders()
                .filter((seeder) => seeder.name === 'ModuleMetadataSeederService')
                .map((seeder) => seeder.instance)
                .pop();
            if (!seeder) {
                this.logger.error(`Seeder service ModuleMetadataSeederService not found. Does your service have a seed() method?`);
            }
            else {
                await seeder.seed();
            }
        }
        else {
            this.logger.debug(`Skipping the Module Metadata Seeder Service as part of post-process code generation`);
        }
        if (config.runSolidIngestion) {
            this.logger.debug(`Running the Solid ingestion command as part of post-process code generation`);
        }
    }
};
exports.ServiceController = ServiceController;
__decorate([
    (0, public_decorator_1.Public)(),
    (0, common_1.Get)('ping'),
    openapi.ApiResponse({ status: 200 }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ServiceController.prototype, "pingPong", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Post)('seed'),
    openapi.ApiResponse({ status: 201 }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], ServiceController.prototype, "seedData", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Post)('code-generation/post-process'),
    openapi.ApiResponse({ status: 201 }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], ServiceController.prototype, "postProcessCodeGeneration", null);
exports.ServiceController = ServiceController = ServiceController_1 = __decorate([
    (0, common_1.Controller)(''),
    (0, swagger_1.ApiTags)("Solid Core"),
    __metadata("design:paramtypes", [solid_registry_1.SolidRegistry,
        ai_interaction_service_1.AiInteractionService,
        mq_message_service_1.MqMessageService,
        error_mapper_service_1.ErrorMapperService,
        ingest_metadata_service_1.IngestMetadataService])
], ServiceController);
//# sourceMappingURL=service.controller.js.map