"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSecurityEval = void 0;
const logger_1 = __importDefault(require("../../../logger"));
const activityLogService_1 = require("../../services/activityLogService");
const securityEvalService_1 = require("../../services/securityEvalService");
const createSecurityEval = async (req, res) => {
    try {
        const { config, force, verbose, delay, user, projectId, orgId: workspaceId, applicationIds, maxConcurrency, securityConfigId, isCustomProvider = false, } = req.body;
        const token = req.headers['x-access-token'] || req.headers.authorization;
        const apiKey = (typeof req.body?.apiKey === 'string' ? req.body.apiKey : undefined) ||
            (typeof req.headers['x-api-key'] === 'string' ? req.headers['x-api-key'] : undefined);
        const { userId, userName } = (0, activityLogService_1.getUserInfo)(req);
        const result = await securityEvalService_1.securityEvalService.createSecurityEval({
            config,
            force,
            verbose,
            delay,
            user,
            projectId,
            orgId: req.body.orgId,
            workspaceId: workspaceId || req.body.orgId,
            applicationIds,
            maxConcurrency,
            securityConfigId,
            isCustomProvider,
            token,
            apiKey,
            userId,
            userName,
        });
        // Check if result is an error response
        if ('success' in result && result.success === false) {
            res.status(400).json(result);
            return;
        }
        // Success response
        res.json(result);
    }
    catch (error) {
        logger_1.default.error(`Error while security eval: ${error.message}`);
        res.status(500).json({
            success: false,
            message: error.message || 'Error while security eval',
        });
    }
};
exports.createSecurityEval = createSecurityEval;
//# sourceMappingURL=create-security-eval.js.map