<?php
namespace Claromentis\Infocapture\Subscriber;

$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] ?: array()) + array("_d0407c814a49347e" . "44aeaf3f7856927f" => base64_decode("T25Vbmxpa2" . "U="), "_085a57daeaa7eb0" . "1c5adc7d4956ca1e" . "c" => base64_decode("T25Ma" . "Wtl"), "aggrega" . "tion" => base64_decode("YWdncmVnYXR" . "pb24="), "_da9102682d361b8bbba479dd35a6a" . "5a6" => base64_decode("bGlr" . "ZV9j" . "b3Vu" . "dA=="), "obj" . "ect" . "_id" => base64_decode("b2JqZ" . "WN0X2" . "lk"));
use Claromentis\Core\Event\EventSubscriberInterface;
use Claromentis\Core\Event\GenericEvent;
use Claromentis\Core\Like\LikeEvents;
use Claromentis\Core\Like\LikesRepository;
use HDIssue;




class TicketLikeSubscriber implements EventSubscriberInterface
{
    
    
    
    
    private $likes_repo;
    
    
    
    
    private HDIssue $hd_issue;
    public function __construct(LikesRepository $_d9545fdd786c9a15186743b3fd0af9ff, HDIssue $_4ada5869286e9a58f9116abae0cfae31)
    {
        $this->likes_repo = $_d9545fdd786c9a15186743b3fd0af9ff;
        $this->hd_issue = $_4ada5869286e9a58f9116abae0cfae31;
    }
    public static function getSubscribedEvents() : array
    {
        return [LikeEvents::OBJECT_LIKED => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_085a57daeaa7eb01" . "c5adc7d4956ca1ec"], LikeEvents::OBJECT_UNLIKED => $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_d0407c814a4934" . "7e44aeaf3f78569" . "27f"]];
    }
    public function OnLike(GenericEvent $event)
    {
        if (!$this->isIssueLikeEvent($event)) {
            return;
        }
        $_7c7f9b97a77342fe69e4b9ce8802e8d1 = $this->updateLikeCountProperty($event->getArgument($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["obje" . "ct_i" . "d"]));
    }
    public function OnUnlike(GenericEvent $event)
    {
        if (!$this->isIssueLikeEvent($event)) {
            return;
        }
        $_7c7f9b97a77342fe69e4b9ce8802e8d1 = $this->updateLikeCountProperty($event->getArgument($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["ob" . "je" . "ct" . "_i" . "d"]));
    }
    
    
    
    
    
    private function updateLikeCountProperty(int $_39638557be821c8556d28efa25c94ff1) : bool
    {
        $_da9102682d361b8bbba479dd35a6a5a6 = $this->likes_repo->GetCount(AGGREGATION_IC_ISSUE, $_39638557be821c8556d28efa25c94ff1);
        $this->hd_issue->Load($_39638557be821c8556d28efa25c94ff1);
        $this->hd_issue->SetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_da91026" . "82d361b8" . "bbba479d" . "d35a6a5a" . "6"], $_da9102682d361b8bbba479dd35a6a5a6);
        return $this->hd_issue->Save();
    }
    
    
    
    
    
    private function isIssueLikeEvent(GenericEvent $event) : bool
    {
        return $event->hasArgument($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["aggre" . "gatio" . "n"]) && $event->getArgument($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["aggregatio" . "n"]) === AGGREGATION_IC_ISSUE;
    }
}