
import dotenv from 'dotenv';
import path from 'path';

// Load environment variables from .env file
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
// Fallback to .env.example if .env doesn't exist or doesn't have keys (though dotenv doesn't overwrite)
dotenv.config({ path: path.resolve(__dirname, '../../.env.example') });

import EmailService from '../services/EmailService';

async function main() {
    const testEmail = process.env.TEST_EMAIL || 'delivered@resend.dev';

    console.log(`Testing email sending to: ${testEmail}`);
    console.log(`Using API Key: ${process.env.RESEND_API_KEY ? '******' + process.env.RESEND_API_KEY.slice(-4) : 'NOT SET'}`);
    console.log(`From Email: ${process.env.EMAIL_FROM}`);

    // 1. Welcome Email
    console.log('\n--- Testing Welcome Email ---');
    const welcomeResult = await EmailService.sendWelcomeEmail(testEmail, 'Test User');
    console.log('Welcome Email Result:', welcomeResult ? 'SUCCESS' : 'FAILED');

    // 2. Forgot Password Email
    console.log('\n--- Testing Forgot Password Email ---');
    const forgotResult = await EmailService.sendPasswordResetEmail(testEmail, 'http://localhost:3000/reset-password?token=test-token');
    console.log('Forgot Password Email Result:', forgotResult ? 'SUCCESS' : 'FAILED');

    // 3. Subscription Confirmation Email
    console.log('\n--- Testing Subscription Confirmation Email ---');
    const subResult = await EmailService.sendSubscriptionConfirmationEmail(testEmail, 'Test User', 'Premium Plan');
    console.log('Subscription Email Result:', subResult ? 'SUCCESS' : 'FAILED');
}

main().catch(console.error);
