// 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": "66347b42b96a009ef1010998",
                    "nm": "inapp amit1",
                    "sd": 1714703400000,
                    "ed": 1714888457000,
                    "st": "ACTIVE",
                    "t": "IN-APP",
                    "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": {
                        "mode": "Fullscreen",
                        "ni": "https://appicewebcdn.appice.io//1713265643613_jM38eudysD6dqdNInOaLte0Q.jpg",
                        "et": "dl",
                        "aurl": "https://www.google.co.in/",
                        "at": "Close",
                        "sa": true,
                        "atc": "#2c2e68",
                        "htc": "#ef2525",
                        "dtc": "#0c370b",
                        "bgc": "#6d7b23",
                        "cdata": {
                            "aurl": "https://www.google.co.in/"
                        }
                    },
                    "allweek": true,
                    "allday": true,
                    "aud": {
                        "who": [
                            {
                                "operand": "did",
                                "operator": "eq",
                                "e_operator": "AND",
                                "value": "3a3ab5e3-4c68-4604-852f-de4775333a62",
                                "category": "Device"
                            }
                        ],
                        "userQ": "IChTRUxFQ1QgRElTVElOQ1QgczEuZGlkIEZST00gYXBwX3VzZXJzXzViZWJlOTNjMjVkNzA1NjkwZmZiYzc1OCBBUyBzMSBXSEVSRSBkaWQgPScxZjQ5N2FiMy1lYTQ0LTRhYTUtYjg0OC0wNWFjZjg1OWRmMmUnICk=",
                        "what": [],
                        "where": [],
                        "when": []
                    }
                },
                {
                    "_id": "xxxxx",
                    "tid": "xxxxx",
                    "t": "FEEDBACK",
                    "sd": 1714715476000000,
                    "ed": 1717393876856,
                    "st": 1714715296856,
                    "delays": 0,
                    "delayi": 0,
                    "delayu": ""
                }],
                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
    });