<?php

namespace Shm\ShmIntegrations\OneSignal;

use Shm\ShmDB\mDB;

class OneSignalPushMsg
{


    private $ownerID;
    private $ownerCollection;

    public function owner($ownerID, $ownerCollection)
    {
        $this->ownerID = $ownerID;
        $this->ownerCollection = $ownerCollection;
        return $this;
    }

    public function send($title, $body)
    {
        if (!$this->ownerID || !$this->ownerCollection) {
            return;
        }

        $subscriptions = mDB::collection("_onePushSubscriptions")->aggregate([

            [
                '$match' => [
                    'owner' => $this->ownerID,
                    'ownerCollection' => $this->ownerCollection,
                ]
            ],
            '$group' => [
                '_id' => '$appId',
                'playerIds' => [
                    '$push' => '$playerId',
                ],
            ],

        ])->toArray();

        /*

        if (!$subscriptions) {
            return;
        }

        $appId = $subscriptions['_id'] ?? null;
        $playerIds = $subscriptions['playerIds'] ?? [];*/
    }
}
