import { MailerService } from '@nestjs-modules/mailer';
import { Injectable } from '@nestjs/common';
import { ConfigurationService } from '../config/configuration.service';

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

  /**
   * How to send an Email
   *
   * await this.mail.sendReplyMessage({
   *   to: 'dev@gmail.com',
   *   data: { message: 'aa', answer: 'bb' },
   * }),
   */
  async sendReplyMessage(to: string, message: string, answer: string) {
    const title = `پاسخ به پیام شما - ${this.config.app.name}`;

    await this.mailerService.sendMail({
      to,
      subject: title,
      text: `پاسخ به پیام شما`,
      template: 'reply-message',
      context: {
        message,
        answer,
        app_name: this.config.app.name,
        title,
      },
    });
  }

  /**
   * How to send an Email
   *
   * await this.mail.sendReplyMessage({
   *   to: 'dev@gmail.com',
   *   data: { answer: 'bb' },
   * }),
   */
  async sendReplyCooperate(to: string, answer: string) {
    const title = `پاسخ به درخواست همکاری شما - ${this.config.app.name}`;

    await this.mailerService.sendMail({
      to,
      subject: title,
      text: `پاسخ به درخواست همکاری شما`,
      template: 'reply-cooperate',
      context: {
        answer,
        app_name: this.config.app.name,
        title,
      },
    });
  }
}
