<?php
namespace Claromentis\Onesignal\Controller;

$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"] ?: array()) + array("_d299c376c3e14d3a" . "3e2dfeafacffaca7" => base64_decode("REVMRVRFIEZST00gb25lc2lnbmFsX3VzZXJzIFdIRVJFIHBsYXllcl9pZD1zdHI6" . "cGlk"), "_2ee1f1953c8" . "2229140ddaf2" . "37892ec89" => base64_decode("c3RyOnBsYXllc" . "l9pZA=="), "_3efc5ba7bf51c" . "a70907f5e65ab6" . "02ec1" => base64_decode("SW50ZXJuYWwgU2" . "VydmVyIEVycm9y"), "_87daa84e346f6420a3f3426" . "e05d16a7b" => base64_decode("Lw=" . "="), "_49545c7d347e8eb5991e3eaa6ea" . "076d3" => base64_decode("YXBw" . "X2lk"), "_0877a0b48cf424a0de57a" . "453ce95e30c" => base64_decode("aW50OnVzZ" . "XJfaWQ="), "_7f3830a9" . "77cea4ad8" . "29278295a" . "c7007f" => base64_decode("cGxheWVyLWl" . "k"), "_38afcc04010dcc90" . "780f504d1ea5854b" => base64_decode("c3RyOnVzZXJf" . "YWdlbnQ="), "_d717cb1f25a45c3a3bbd0784" . "8333867d" => base64_decode("REVMRVRFIEZST00gb25lc2lnbmFsX3VzZXJzIFdIRVJFIHBsY" . "Xllcl9pZD1zdHI6cGlkIEFORCB1c2VyX2lkPWludDp1aWQ="), "_ddce17bd96ac6ba0e7c14b" . "8cc6a3b88f" => base64_decode("Tm8gT25lU2lnb" . "mFsIHBsYXllci" . "BJRCBnaXZlbg=" . "="), "_0982aea110a4b" . "9c2d9cbb77f1f3" . "78290" => base64_decode("SFRUUF9VU0VSX0FHRU" . "5U"), "_8521a1e0547e2d98ee3136e5f" . "95ae7ac" => base64_decode("RmFpbGVkIHRvIHVucmVnaXN0ZXIgT25lU2lnbmFsIHBsYXllciBJ" . "RA=="), "_4b5e91a0a6f7f822ac389ad9a3fb0" . "ee2" => base64_decode("c3V" . "jY2" . "Vzc" . "w=="), "_6923f62609955ad066" . "b2aa54ed6ceffd" => base64_decode("b25lc2ln" . "bmFsX3Vz" . "ZXJz"), "_4d046d5" . "121cfe3d" . "589b901f" . "2642dfc8" . "e" => base64_decode("cGxh" . "eWVy" . "X2lk"), "_c91b0ff19f81a88" . "73a4593a23719472" . "c" => base64_decode("cn" . "Ry" . "aW" . "0="), "_af604f5cf0" . "75b8f27c57b" . "e57f01a7588" => base64_decode("RmFpbGVkIHRvIHJlZ2lzdGVyIE9uZVNpZ25hbCBwbGF5ZXIgS" . "UQ="), "_e06da3ffb" . "a2e84b8e6f" . "94bd2d6ca3" . "c52" => base64_decode("Y3JlYXRlX2ludGVybmFs" . "X2xpbms="), "_5d9dc4535" . "307a25ed5e" . "a3f94ec97c" . "936" => base64_decode("YmFzZV9" . "1cmw="));
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Integration\Repository;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Onesignal\OnesignalClient;
use Psr\Http\Message\ServerRequestInterface;
use RestExBadRequest;
use RestExError;
use RestExNotFound;
use RestFormat;
use Claromentis\Core\DAL;
class OnesignalController
{
    
    
    
    
    protected $formatter;
    
    
    
    
    protected $db;
    
    
    
    
    
    
    
    public function __construct(RestFormat $formatter, DAL\Db $db)
    {
        $this->formatter = $formatter;
        $this->db = $db;
    }
    
    
    
    
    
    
    
    
    protected function GetPlayerId(ServerRequestInterface $request)
    {
        $_ed5f03d686c37933b5943f295c6b4a43 = $this->formatter->GetJson($request);
        if (!isset($_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_7f3830a977ce" . "a4ad829278295" . "ac7007f"]]) && empty($_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_7f3830a977c" . "ea4ad8292782" . "95ac7007f"]])) {
            throw new RestExBadRequest($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_ddce17bd96ac6ba0e7c14b8c" . "c6a3b88f"]);
        }
        return $_ed5f03d686c37933b5943f295c6b4a43[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_7f3830a977cea4ad829278295ac70" . "07f"]];
    }
    
    
    
    
    
    
    
    
    
    
    public function AssociatePlayerId(ServerRequestInterface $request, SecurityContext $context)
    {
        $_4d046d5121cfe3d589b901f2642dfc8e = $this->GetPlayerId($request);
        $user_id = $context->GetUserId();
        $_f36b7c73011d1a43d8d280d096557b46 = $request->getServerParams()[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_0982aea110a4b" . "9c2d9cbb77f1f3" . "78290"]] ?? null;
        try {
            $this->db->DoTransaction(function (DAL\Interfaces\DbInterface $db) use($_4d046d5121cfe3d589b901f2642dfc8e, $user_id, $_f36b7c73011d1a43d8d280d096557b46) {
                $db->unsafe_query = true;
                $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_d299c376c3e14d3a3e2dfeafac" . "ffaca7"], $_4d046d5121cfe3d589b901f2642dfc8e);
                $_d88b50ddb42db648a9c7ac08065b9409 = new DAL\QueryInsert($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_6923f62609955ad066b2aa54ed6c" . "effd"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_0877a0b48cf424a0de57a45" . "3ce95e30c"] => $user_id, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_2ee1f1953c8222914" . "0ddaf237892ec89"] => $_4d046d5121cfe3d589b901f2642dfc8e, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_38afcc04010dcc907" . "80f504d1ea5854b"] => $_f36b7c73011d1a43d8d280d096557b46]);
                $db->query($_d88b50ddb42db648a9c7ac08065b9409);
            });
        } catch (DAL\Exceptions\TransactionException $e) {
            throw new RestExError($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_af604f5cf075b8f27c57be57f0" . "1a7588"], 500, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_3efc5ba7bf5" . "1ca70907f5e6" . "5ab602ec1"], $e);
        }
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4b5e91a0a6f7f822" . "ac389ad9a3fb0ee2"] => true, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_4d046d5121cfe3d589b901" . "f2642dfc8e"] => $_4d046d5121cfe3d589b901f2642dfc8e]);
    }
    
    
    
    
    
    
    
    
    
    
    public function DisassociatePlayerId(ServerRequestInterface $request, SecurityContext $context)
    {
        $_4d046d5121cfe3d589b901f2642dfc8e = $this->GetPlayerId($request);
        $user_id = $context->GetUserId();
        try {
            $this->db->DoTransaction(function (DAL\Interfaces\DbInterface $db) use($_4d046d5121cfe3d589b901f2642dfc8e, $user_id) {
                $db->query($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_d717cb1f25" . "a45c3a3bbd0" . "7848333867d"], $_4d046d5121cfe3d589b901f2642dfc8e, $user_id);
            });
        } catch (DAL\Exceptions\TransactionException $e) {
            throw new RestExError($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_8521a1e0547e2d98ee" . "3136e5f95ae7ac"], 500, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_3efc5ba7bf51" . "ca70907f5e65a" . "b602ec1"], $e);
        }
        return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_4b5e91a0a6f7f8" . "22ac389ad9a3fb0" . "ee2"] => true]);
    }
    
    
    
    
    
    
    
    
    
    
    
    public function ServeAppInfo(OnesignalClient $client)
    {
        $_49545c7d347e8eb5991e3eaa6ea076d3 = $client->GetAppId();
        if (isset($_49545c7d347e8eb5991e3eaa6ea076d3)) {
            $_5d9dc4535307a25ed5ea3f94ec97c936 = $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_c91b0ff19f" . "81a8873a459" . "3a23719472c"]($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_e06da3ffba2e" . "84b8e6f94bd2d" . "6ca3c52"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_87daa84e346f6420a3f3426e05d1" . "6a7b"]), $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_87daa84e346f6420a3f3426e05d16" . "a7b"]);
            return new JsonPrettyResponse([$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_5d9dc4535307a25ed5ea3f94ec" . "97c936"] => $_5d9dc4535307a25ed5ea3f94ec97c936, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_49545c7d347e8eb5991e" . "3eaa6ea076d3"] => $_49545c7d347e8eb5991e3eaa6ea076d3]);
        }
        throw new RestExNotFound();
    }
}