<?php

namespace Cobblestone\CcLogin\Service;

class PushService extends AbstractCCService
{
    /**
     * @param int $userId
     * @param string $name
     * @param string $title
     * @param string $body
     * @param array $customData
     * @return array|null
     */
    public function sendPushNotification(string $xApiKey, int $userId, string $name, string $title, string $body, array $customData = []): ?array
    {
        $payload = [
            "name" => $name,
            "title" => $title,
            "body" => $body,
        ];

        if (!empty($customData)) {
            $payload["custom_data"] = $customData;
        }

        $headers = [
            "Content-Type: application/json",
            "x-api-key: $xApiKey",
        ];

        return $this->callApi("/user/$userId/pushmessage", $headers, json_encode($payload));
    }
}