import { MailerModule } from '@nestjs-modules/mailer';
import { forwardRef, Module } from '@nestjs/common';
import { MailsService } from './services/mails.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MailProcessor } from './process/mail.processor';
import { BidsModule } from '../bids/bids.module';
@Module({
  imports: [
    forwardRef(() => BidsModule),
    MailerModule.forRootAsync({
      imports: [ConfigModule],

      useFactory: async (config: ConfigService) => ({
        transport: {
          host: config.get<string>('MAIL_SERVER'),
          port: 465,
          secure: true, // true nếu port là 465
          auth: {
            user: config.get<string>('MAIL_USER'),
            pass: config.get<string>('MAIL_PASSWORD'),
          },
        },
        defaults: {
          from: `"Bids" <${config.get<string>('MAIL_USER')}>`,
        },
      }),

      inject: [ConfigService],
    }),
  ],
  providers: [MailsService, MailProcessor],
  exports: [MailsService],
})
export class MailsModule {}
