"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmtpProvider = void 0;
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
/*@ts-ignore*/
var { __ΩScopedLogger } = require('@deepkit/logger');
const nodemailer_1 = require("nodemailer");
const app_1 = require("../../app");
class SmtpProvider {
    constructor(config, logger) {
        this.config = config;
        this.logger = logger;
        this.transporter = (0, nodemailer_1.createTransport)({
            host: this.config.SMTP_HOST,
            port: this.config.SMTP_PORT,
            secure: this.config.SMTP_TLS,
            auth: this.config.SMTP_USER
                ? {
                    user: this.config.SMTP_USER,
                    pass: this.config.SMTP_PASSWORD_SECRET
                }
                : undefined
        });
        if (!this.config.SMTP_HOST) {
            throw new Error('SMTP_HOST is not set');
        }
    }
    async send(message) {
        const response = await this.transporter.sendMail({
            from: message.from,
            to: message.to,
            subject: message.subject,
            html: message.message,
            text: message.plainMessage,
            replyTo: message.replyTo,
            attachments: message.attachments?.map(__assignType(attachment => ({
                filename: attachment.name,
                content: attachment.content,
                contentType: attachment.contentType,
                cid: attachment.cid
            }), ['attachment', '', 'P"2!"/"']))
        });
        return response.messageId;
    }
}
exports.SmtpProvider = SmtpProvider;
SmtpProvider.__type = ['transporter', function () { return (0, nodemailer_1.createTransport)({
        host: this.config.SMTP_HOST,
        port: this.config.SMTP_PORT,
        secure: this.config.SMTP_TLS,
        auth: this.config.SMTP_USER
            ? {
                user: this.config.SMTP_USER,
                pass: this.config.SMTP_PASSWORD_SECRET
            }
            : undefined
    }); }, () => app_1.BaseAppConfig, 'config', () => __ΩScopedLogger, 'logger', 'constructor', 'PreparedMessageProperties', 'message', 'send', 'MailProvider', 'SmtpProvider', '!3!;>"PP7#2$;n%2&;"0\'P"w(2)&`0*5"w+x"w,'];
//# sourceMappingURL=smtp.js.map