import admin from "firebase-admin";
import serviceAccount from "../googlefirebasePushnotification.json" with { type: "json" };
export const sendPushNotification = async (userToken,title, message) => {
  // const admin = require("firebase-admin");
  // const serviceAccount = require("./path/to/your-firebase-adminsdk.json");

  if (!admin.apps.length) {
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
    });
  }

  const payload = {
    notification: {
      title: title,
      body: message,
    },
    token: userToken
  };

  try {
    const response = await admin.messaging().send(payload);
    console.log("Successfully sent message:", response);
  } catch (error) {
    console.error("Error sending message:", error);
  }
};
