<?php

require_once __DIR__ . '/firebase_token.php';

function sendFirebasePush($token,$type,$breakdown_id)
{

    $access_token = getFirebaseAccessToken();

    $project_id = "jb26assist";

    $url = "https://fcm.googleapis.com/v1/projects/$project_id/messages:send";

    $payload = [
        "message"=>[
            "token"=>$token,
            "data"=>[
                "type"=>$type,
                "breakdown_id"=>(string)$breakdown_id
            ]
        ]
    ];

    $headers = [
        "Authorization: Bearer $access_token",
        "Content-Type: application/json"
    ];

    $ch = curl_init();

    curl_setopt_array($ch,[
        CURLOPT_URL=>$url,
        CURLOPT_POST=>true,
        CURLOPT_HTTPHEADER=>$headers,
        CURLOPT_RETURNTRANSFER=>true,
        CURLOPT_POSTFIELDS=>json_encode($payload)
    ]);

    $response = curl_exec($ch);

    curl_close($ch);

    return $response;
}