import { MailerService } from '@nestjs-modules/mailer';
import { Injectable } from '@nestjs/common';

@Injectable()
export class EmailService {
  constructor(private readonly mailerService: MailerService) {}

  async sendResetPasswordEmail(email: string, resetCode: string): Promise<void> {
    const mailOptions = {
      to: email,
      subject: 'Reset your password',
      html: `<p>Your reset code is <b>${resetCode}</b></p>`,
    };
    try {
      await this.mailerService.sendMail(mailOptions);
    } catch (error) {
      console.error(error);
      throw new Error('Error sending email');
    }
  }

  async sendConfirmationCode(email: string, confirmationCode: string): Promise<void> {
    const mailOptions = {
      to: email,
      subject: 'Confirm your email',
      html: `<p>Your confirmation code is <b>${confirmationCode}</b></p>`,
    };
    try {
      await this.mailerService.sendMail(mailOptions);
    } catch (error) {
      console.error(error);
      throw new Error('Error sending email');
    }
  }
}
