// src/config/mails/mail.config.ts
import { ConfigService } from '@nestjs/config';
import * as nodemailer from 'nodemailer';

const createTransporter = (
  configService: ConfigService,
): nodemailer.Transporter => {
  const mailHost = configService.get<string>('mail.host') || 'localhost';
  const mailPort = configService.get<number>('mail.port') || 465;
  const mailUsername = configService.get<string>('mail.username');
  const mailPassword = configService.get<string>('mail.password');

  const transporter = nodemailer.createTransport({
    host: mailHost,
    port: mailPort,
    secure: mailPort === 465, // true for 465, false for other ports
    auth: {
      user: mailUsername,
      pass: mailPassword,
    },
  });

  return transporter;
};

export default createTransporter;
