import { Injectable } from '@nestjs/common'
import { DASHBOARD_URL } from '../../../config'
import { EmailService, MAILER_TEMPLATES, SendMailOptions } from '../../../global'

@Injectable()
export class AuthEmailService {
	constructor(private readonly _emailService: EmailService) {}

	/**
	 * Sends a confirmation email to the user.
	 *
	 * @param email - The email address to send the confirmation email to
	 * @param token - The token to use in the confirmation email
	 */
	sendConfirmationEmail(email: string, token: string): Promise<void> {
		const mail: SendMailOptions = {
			to: email,
			subject: 'Activate your account - KADiCon',
			template: MAILER_TEMPLATES.AUTH.EMAIL_CONFIRMATION.DEFAULT,
			context: {
				verification_url: `${DASHBOARD_URL}/onboarding?token=${token}`,
			},
		}

		return this._emailService.send(mail)
	}

	/**
	 * Sends a reset password email to the user.
	 *
	 * @param email - The email address to send the reset password email to
	 * @param token - The token to use in the reset password email
	 */
	sendResetPasswordEmail(email: string, token: string): Promise<void> {
		const mail: SendMailOptions = {
			to: email,
			subject: 'Reset password - KADiCon',
			template: MAILER_TEMPLATES.AUTH.RESET_PASSWORD.DEFAULT,
			context: {
				kadi_app_url: DASHBOARD_URL,
				reset_url: `${DASHBOARD_URL}/reset-password?token=${token}`,
			},
		}

		return this._emailService.send(mail)
	}
}
