"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.emailRouter = void 0;
const express_1 = require("express");
const logger_1 = __importDefault(require("../../logger"));
const callControlPlaneApi_1 = require("../../util/callContolPlane/callControlPlaneApi");
const emailRouter = (0, express_1.Router)();
exports.emailRouter = emailRouter;
// Send welcome email
emailRouter.post('/welcome', async (req, res) => {
    try {
        const { dashboardUrl, trusysUrl } = req.body;
        const token = req.headers['x-access-token'] || req.headers.authorization;
        if (!dashboardUrl || !trusysUrl) {
            res.status(400).json({
                error: 'Missing required fields: dashboardUrl and trusysUrl are required',
            });
            return;
        }
        // Call control plane API to send welcome email
        const response = await (0, callControlPlaneApi_1.callControlPlane)('/trusys-emails/welcome-new-user', {
            method: 'POST',
            params: {
                dashboardUrl,
                trusysUrl,
            },
        }, token);
        if (response?.error) {
            logger_1.default.error(`Error sending welcome email: ${response.error}`);
            res.status(500).json({
                error: 'Failed to send welcome email',
                details: response.error,
            });
            return;
        }
        logger_1.default.info('Welcome email sent successfully');
        res.status(200).json({
            success: true,
            message: 'Welcome email sent successfully',
        });
    }
    catch (error) {
        logger_1.default.error(`Error in welcome email endpoint: ${error}`);
        res.status(500).json({
            error: 'Internal server error while sending welcome email',
        });
    }
});
//# sourceMappingURL=email.js.map