const axios = require('axios');

async function verifyRecaptcha(token) {
  const secretKey = process.env.RECAPTCHA_SECRET_KEY; // Replace with your reCAPTCHA secret key
  const url = 'https://www.google.com/recaptcha/api/siteverify';

  try {
    const response = await axios.post(url, {
      secret: secretKey,
      response: token
    });

    const { success, score } = response.data;
    return { success, score };
  } catch (error) {
    console.error('reCAPTCHA verification failed:', error.message);
    return { success: false, score: null };
  }
}

module.exports = { verifyRecaptcha };