"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PulseMonitoringController = void 0;
const logger_1 = __importDefault(require("../../../logger"));
const pulse_1 = require("../../../validators/pulse");
const pulseMonitoringService_1 = require("../../services/pulseMonitoringService");
const PulseMonitoringController = {
    async getMonitoringConfig(req, res) {
        try {
            logger_1.default.info('Monitoring config endpoint called');
            const { applicationId } = req?.query ?? {};
            const pulseData = await pulseMonitoringService_1.pulseMonitoringService.getMonitoringConfig({
                applicationId: applicationId,
            });
            res.json({
                success: true,
                data: pulseData,
            });
        }
        catch (error) {
            logger_1.default.error(`Error in monitoring config controller: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
    async createMonitoring(req, res) {
        try {
            logger_1.default.info('Creating monitoring');
            const { applicationId, logLocation, serviceProvider, locationUrl, samplingFrequency, samplingPercentage, samplingCount, evaluationWindow, metrics, pluginsByCategory, apiKey, accessKey, secretKey, awsRegion, tenantId, clientId, clientSecret, } = req?.body ?? {};
            const { orgId, projectId, } = req?.query ?? {};
            const validationResult = pulse_1.PulseMonitoringSchema.validate({
                applicationId,
                logLocation,
                serviceProvider,
                locationUrl,
                samplingFrequency,
                samplingPercentage,
                pluginsByCategory,
                samplingCount,
                evaluationWindow,
                metrics,
                apiKey,
                accessKey,
                secretKey,
                awsRegion,
                tenantId,
                clientId,
                clientSecret,
            });
            if (validationResult?.error) {
                res.status(400).json({
                    success: false,
                    message: validationResult?.error?.message,
                    error: validationResult?.error,
                });
                return;
            }
            const pulseData = await pulseMonitoringService_1.pulseMonitoringService.createMonitoring({
                applicationId: applicationId,
                logLocation,
                serviceProvider,
                locationUrl,
                samplingFrequency,
                samplingPercentage,
                samplingCount,
                evaluationWindow,
                metrics,
                pluginsByCategory,
                apiKey,
                accessKey,
                secretKey,
                awsRegion,
                tenantId,
                clientId,
                clientSecret,
                projectId: projectId,
                workspaceId: orgId,
            });
            res.json({
                success: true,
                data: pulseData,
            });
        }
        catch (error) {
            logger_1.default.error(`Error in monitoring controller: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
    async updateMonitoring(req, res) {
        try {
            logger_1.default.info('Updating monitoring');
            const { applicationId, samplingFrequency, samplingPercentage, samplingCount, evaluationWindow, metrics, pluginsByCategory, } = req?.body ?? {};
            if (!applicationId) {
                res.status(400).json({
                    success: false,
                    message: 'applicationId is required',
                });
                return;
            }
            const result = await pulseMonitoringService_1.pulseMonitoringService.updateMonitoring({
                applicationId,
                samplingFrequency,
                samplingPercentage,
                samplingCount,
                evaluationWindow,
                metrics,
                pluginsByCategory,
            });
            res.json({ success: true, data: result });
        }
        catch (error) {
            logger_1.default.error(`Error in update monitoring controller: ${error}`);
            res.status(500).json({
                success: false,
                message: error.message,
                error: error.message,
            });
        }
    },
};
exports.PulseMonitoringController = PulseMonitoringController;
//# sourceMappingURL=pulse-monitoring.js.map