"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCustomAIBundle = void 0;
const customAIApplicationUpload_1 = require("../../middlewares/customAIApplicationUpload");
const customAIApplicationService_1 = require("../../services/customAIApplicationService");
const validateCustomAIBundle = async (req, res) => {
    const zipPath = req.file?.path;
    try {
        if (!req.file) {
            res.status(400).json({ success: false, message: 'zipFile is required' });
            return;
        }
        const service = new customAIApplicationService_1.CustomAIApplicationService();
        const { language, applicationPath, orgId, projectId } = customAIApplicationService_1.CustomAIApplicationService.parseRequestFields(req.body);
        if (!orgId || !projectId) {
            res.status(400).json({ success: false, message: 'orgId and projectId are required' });
            return;
        }
        if (!language) {
            res.status(400).json({ success: false, message: 'language must be python, js, or go' });
            return;
        }
        if (!applicationPath) {
            res.status(400).json({ success: false, message: 'applicationPath is required' });
            return;
        }
        const result = service.validateBundleFromPath({
            zipFilePath: zipPath,
            language,
            applicationPath,
        });
        res.json({
            success: result.valid,
            data: result,
            message: result.valid ? 'Bundle validation passed' : result.errors.join('; '),
        });
    }
    catch (error) {
        res.status(500).json({
            success: false,
            message: error instanceof Error ? error.message : 'Validation failed',
        });
    }
    finally {
        (0, customAIApplicationUpload_1.cleanupCustomAIUploadFile)(zipPath);
    }
};
exports.validateCustomAIBundle = validateCustomAIBundle;
//# sourceMappingURL=validate-custom-ai-bundle.js.map