<?php

function firebase_notification($title, $body, $mst_user_firebase)
{
    $ci = &get_instance();
    $fcmUrl = 'https://fcm.googleapis.com/fcm/send';

    $notification = array(
        'type' => 1,
        'title' => $title,
        'body' => $body,
        'click_action' => 'main_activity',
        'tipe' => 'callback',
        'sound' => 'default',
        'icon'  => 'ic_notification',
    );

    $fcmNotification = [
        //'registration_ids' => '', 
        'to'        => $mst_user_firebase,
        'data' => $notification,
        'notification' => $notification,
        'priority' => 'high',
        'apns-priority' => '5'
    ];

    $headers = [
        'Authorization: key=' . $ci->config->item('firebase_key'),
        'Content-Type: application/json'
    ];


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $fcmUrl);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
    $result = curl_exec($ch);
    curl_close($ch);
}
