const otpModel = require("../models/otp");

const generateOTP = async (req) => {
    let { email } = req.body;
    email = email?.toLowerCase();
    const otp = Math.floor(1000 + Math.random() * 9000).toString();

    const newOTP = new otpModel({
        email: email,
        OTP: otp
    });
    const result = await newOTP.save();
    return result
};

const verifyOTP = async (req) => {
    let { email, OTP } = req.query;
    email = email?.toLowerCase()
    const otp = await otpModel.find({ email, OTP});
    return otp
};

module.exports = {
    generateOTP,
    verifyOTP
};