
import admin from "firebase-admin";
import { getMessaging } from "firebase-admin/messaging";
import path from 'path';
import type { NotificationData } from "../types";

var serviceAccount = require(path.resolve(__dirname, '..', 'private', 'my-kaiqiuwang-firebase-adminsdk-fbsvc-8712e14c10.json'));

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

export async function sendNotification(token: string, data: NotificationData, dryRun?: boolean) {
  if (!token) return;
  const messageId = await getMessaging().send({
    token,
    data: data as any,
  }, dryRun);
  return messageId;
}