const nodemailer = require('nodemailer');
const mailConfig = require('../configs/mailConfig');

const accountDeletionRequestEmail = async (toEmail, deletionId) => {

    if (!toEmail || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(toEmail)) {
        throw new Error("Invalid recipient email address");
      }

  const transporter = nodemailer.createTransport(mailConfig);

  const mailOptions = {
    from: `"BOBROS" <customersupport@bobrosone.com>`,
    to: toEmail,
    bcc: ['admin@bobrosconsultancy.com', 'customersupport@bobrosone.com'],
    subject: `Your account deletion request is registered, Your deletion Request ID: ${deletionId} `,
    html: `
    Dear Customer,<br><br>
    We are sorry to see you go. We have registered your account deletion request. 
    We value your decision and respect your privacy. Your BOBROS User Account Deletion request ID: <strong>${deletionId}</strong>.<br><br> 
    If this request is not made by you, please write to us within next 24 hours of receiving this email or contact us on our customer support number. 
    If the request is made by you, sit back and relax, your request will be processed within next -2- working days.<br>
    Please find the detailed Terms & Condition of BOBROS at:<br><a href='https://bobrosone.com/termsandconditions.pdf'>https://bobrosone.com/termsandconditions.pdf</a><br>
    and Privacy Policy at:<br><a href='https://bobrosone.com/PrivacyPolicy.html'>https://bobrosone.com/PrivacyPolicy.html</a><br>for your reference.<br><br>
    You may contact Customer Support at 91-9133 133 456 (Available from 9:30AM to 7:30PM Monday to Saturday except on Holidays) or write to us on <a href='mailto:customersupport@bobrosone.com'>customersupport@bobrosone.com</a> for any queries or assistance.<br><br>
    Thanking you,<br>
    With Regards,<br>
    <strong>Team BOBROS</strong>
    `
  };

  return transporter.sendMail(mailOptions);
};


module.exports = { accountDeletionRequestEmail };


