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

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

  async sendUserConfirmation(user: User) {
    // For now, we don't have a confirmation token flow, just a welcome email
    // If we wanted confirmation, we'd generate a token here or pass it in.
    
    await this.mailerService.sendMail({
      to: user.email,
      // from: '"Support Team" <support@example.com>', // override default from
      subject: 'Willkommen im Smarten Klassenzimmer!',
      template: './confirmation', // `.hbs` extension is appended automatically
      context: { 
        name: user.username,
        // url,
      },
    });
  }

  async sendPasswordReset(user: User, token: string) {
    const url = `http://localhost:5173/reset-password?token=${token}`; // Frontend URL

    await this.mailerService.sendMail({
      to: user.email,
      subject: 'Passwort zurücksetzen',
      template: './reset-password', 
      context: { 
        name: user.username,
        url,
      },
    });
  }
}
