const nodemailer = require("nodemailer");
const addMessageRequest = async (req, res) => {
  try {
    const { Date, Duration, Email, Message, Name, Package, Phone } = req.body;

    const transporter = nodemailer.createTransport({
      host: "premium54.web-hosting.com",
      port: 465,
      secure: true,
      auth: {
        user: "newsletter@gammatourz.com",
        pass: ",LAOn}D@F-[f",
      },
    });

    const mailOptions = {
      from: "Gamma Tourz <newsletter@gammatourz.com>",
      to: "clients@gammatourz.com",
      subject: "New Custom Package Request Received!",
      text: `
  Hi  Team,
  
  You have received a new package request with the following details:
  
  👤 Name: ${Name}
  📧 Email: ${Email}
  📞 Phone: ${Phone}
  📦 Selected Package: ${Package}
  📅 Preferred Date: ${Date}
  ⏳ Duration: ${Duration}
  
  📝 Additional Message:
  ${Message}
  
  Best regards,
 Gamma Tourz
        `.trim(),
    };

    await transporter.sendMail(mailOptions);

    res
      .status(201)
      .json({ message: "Request submitted and Email sent successfully!" });
  } catch (err) {
    console.error(err);
    res
      .status(500)
      .json({ message: "Something went wrong while submitting the request." });
  }
};

module.exports = {
  addMessageRequest,
};
