import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { Module } from '@nestjs/common';
import { join } from 'path';
import { FirebaseAdminModule } from 'src/firebase-admin/firebase-admin.module';
import { DrizzleModule } from '../drizzle/drizzle.module';
import { FileService } from '../file/file.service';
import { GeoModule } from '../geo/geo.module';
import { GeoService } from '../geo/geo.service';
import { UserModule } from '../user/user.module';
import { UserService } from '../user/user.service';
import { MailController } from './mail.controller';
import { MailService } from './mail.service';

@Module({
  imports: [
    DrizzleModule,
    UserModule,
    GeoModule,
    FirebaseAdminModule,
    MailerModule.forRootAsync({
      useFactory: () => ({
        transport: {
          host: 'email-smtp.us-east-2.amazonaws.com',
          secure: false,
          port: 587,
          auth: {
            user: process.env.AMAZON_USER, 
            pass: process.env.AMAZON_PASSWORD, 
          },
        },
        defaults: {
          from: '"No Reply" <noreply@example.com>',
        },
        template: {
          dir: join(__dirname, 'templates'),
          adapter: new HandlebarsAdapter({
            eq: function (a, b) {
              return a === b;
            },
          }),
          options: {
            strict: true,
          },
        },
      }),
    }),
  ],
  providers: [MailService, UserService, FileService, GeoService],
  controllers: [MailController],
})
export class MailModule {}
