// Test email sending functionality
import dotenv from "dotenv";
import { sendWebsiteSubmissionEmail } from "./utils/emailService.js";

dotenv.config();

async function testEmail() {
  console.log("🧪 Testing email functionality...\n");

  const testData = {
    userName: "Test User",
    websiteTitle: "Test Website",
    websiteUrl: "https://example.com",
    category: "Portfolio",
    submissionDate: new Date(),
    paymentOrderID: "TEST123456789",
    paymentAmount: "12.99",
    paymentCurrency: "USD"
  };

  const testEmail = process.argv[2] || "test@example.com";

  console.log("📧 Sending test email to:", testEmail);
  console.log("📊 Test data:", testData);
  console.log("");

  try {
    await sendWebsiteSubmissionEmail(testEmail, testData);
    console.log("\n✅ Email test PASSED!");
    console.log("Check your inbox at:", testEmail);
  } catch (error) {
    console.log("\n❌ Email test FAILED!");
    console.error("Error details:", error.message);
    
    if (error.code === "EAUTH") {
      console.log("\n⚠️  AUTHENTICATION ERROR!");
      console.log("Gmail is blocking the login. You need to:");
      console.log("1. Go to: https://myaccount.google.com/security");
      console.log("2. Enable 2-Step Verification");
      console.log("3. Go to: https://myaccount.google.com/apppasswords");
      console.log("4. Create an App Password for 'Mail'");
      console.log("5. Replace CSSA123!@# with the 16-character app password");
      console.log("6. Update both emailService.js and contactRoute.js");
    }
  }
}

testEmail();
