// Import the Firebase Admin SDK
const admin = require("firebase-admin");

// Initialize Firebase Admin SDK with the path to your service account key file
const serviceAccount = require("/Applications/Projects/FirebaseMessage/appice-77b2f-firebase-adminsdk-yx5ee-5eb73c961e.json");
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
});

// FCM token of the device you want to send the notification to
const deviceFCMToken = "fdY5r83lTtSsAnIkoMxwcT:APA91bEP0CINNPI4-RueMTTzjixlfhW3xlTzLIdMIQJ5lcwWioTdM-fwacQ82GS2YknfdTgr_QfBBl8Kgud08P2pApUVPt7qhis4PkIHBfe1-OfJFidJuKsw5VJOWkoeYwSxI5H_prCK";

// Create the message object
const message = {
    token: deviceFCMToken,
    android: {
        priority: 'high',
        data: {
            message: JSON.stringify({
                ai_tag: "ai_pn",
                activeCampaigns: [{
                    _id: "560e33f914f50d0e8b2f5df4",
                    nm: "20marchtest",
                    sd: 1710901800000,
                    ed: 1714974132000,
                    st: "ACTIVE",
                    t: "PUSH",
                    d: false,
                    fre: {
                        show: "1",
                        rangeStatus: "lt",
                        rangeValue: "",
                        pastDays: "",
                        interval: 0,
                        iUnit: "mm",
                        e: "no",
                        s: "",
                        d: "",
                        l: ""
                    },
                    timeSelector: "ALLDAY",
                    time: [
                        8,
                        20
                    ],
                    delays: 0,
                    delayi: 0,
                    delayu: "",
                    data: {
                        nh: "Platinum Credit Card",
                        nd: "Ge the new Alinma Platimum Credit Card and earn 4x rewards",
                        ni: "https://appice-prod-campaign-images.objectstore.e2enetworks.net/1709564177451_wxUt1YmZiTetyfcUYVg12lbE.png",
                        end: "",
                        eni: "https://appice-prod-campaign-images.objectstore.e2enetworks.net/1709564285196_ofDzUui_Oae_rhUykQHMOo28.png",
                        and: {
                            b: "",
                            i: [

                            ],
                            d: 0,
                            l: 0,
                            g: 0,
                            f: "",
                            m: ""
                        },
                        ty: "",
                        eurl: "",
                        et: "dl",
                        actions: [

                        ],
                        sound: false,
                        vibrate: false,
                        badge: false,
                        fcmid: "fcmid1",
                        did: "3a3ab5e3-4c68-4604-852f-de4775333a62",
                        cdata: [{
                            "state": "openFD",
                            "type": "string"
                        }]
                    },
                    allweek: true,
                    allday: true,
                    aud: {
                        who: [{
                            operand: "did",
                            operator: "eq",
                            e_operator: "AND",
                            value: "3a3ab5e3-4c68-4604-852f-de4775333a62",
                            category: "Device"
                        }],
                        what: [{
                            process: true,
                            state: false,
                            operand: "AddToCart",
                            e_operator: "AND",
                            category: "Events",
                            since: {
                                have: "h"
                            }
                        }],
                        where: [

                        ],
                        when: [

                        ]
                    }
                }],
                sp: "true"
            })
        }
    }
};

console.log(message)

// Send the message
admin.messaging().send(message)
    .then((response) => {
        console.log('Successfully sent message:', response); // Log success message
    })
    .catch((error) => {
        console.error('Error sending message:', error.errorInfo); // Log error message
    });