import nodemailer from "nodemailer";

interface SendEmailOptions {
  to: string;
  subject: string;
  html: string;
}

export async function sendEmail({ to, subject, html }: SendEmailOptions) {
  const password = process.env.EMAIL_PASSWORD;

  if (!password) {
    console.warn(
      "[email] EMAIL_PASSWORD not set — skipping email send to:",
      to
    );
    return;
  }

  const transporter = nodemailer.createTransport({
    host: "smtp.migadu.com",
    port: 465,
    secure: true,
    auth: {
      user: "hunter@repi.fun",
      pass: password,
    },
  });

  await transporter.sendMail({
    from: "AgentLens <hunter@repi.fun>",
    to,
    subject,
    html,
  });
}
