/**
 * Transactional Email Service
 *
 * High-level functions for sending authentication and onboarding emails.
 */

import { sendEmail } from '../core';
import { createOTPEmail, createWelcomeEmail, createPasswordResetEmail } from '../templates';
import { logger } from '@/lib/logger';

/**
 * Send OTP email
 */
export async function sendOTPEmail(
  email: string,
  otp: string,
  language: 'ar' | 'en',
  name?: string,
  purpose: 'login' | 'signup' | 'reset' = 'login'
): Promise<boolean> {
  try {
    // Use professional template service if available, fallback to legacy
    const template = createOTPEmail(otp, language, name, purpose);

    const sent = await sendEmail(email, template);

    if (sent) {
      // Logger will auto-sanitize email in production
      logger.info('OTP email sent', { email, purpose });
    }

    return sent;
  } catch (error) {
    logger.error('Failed to send OTP email', { email, purpose, error });
    return false;
  }
}

/**
 * Send Welcome Email
 */

/**
 * Send welcome email
 */
export async function sendWelcomeEmail(email: string, name: string, language: 'ar' | 'en'): Promise<boolean> {
  const template = createWelcomeEmail(name, language);
  return sendEmail(email, template);
}

/**
 * Send Password Reset Email
 */

/**
 * Send password reset email
 */
export async function sendPasswordResetEmail(email: string, otp: string, language: 'ar' | 'en'): Promise<boolean> {
  const template = createPasswordResetEmail(otp, language);
  return sendEmail(email, template);
}

/**
 * Demo Booking Received Email Template (Immediate - when booking is first made)
 */
